From ef7e03c1c6ca04ddd4049d2e89485be063cfbb17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20Sch=C3=BCrch?= <803221+ardanedh@users.noreply.github.com> Date: Sat, 3 Feb 2024 00:00:00 +0100 Subject: [PATCH] [digitalstrom] Fix initialization of temperature control devices (#16352) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix UnsupportedOperation thrown when adding an element to a fixed-size list. Fixes #10649 * removed static modifier on SUPPORTED_EVENTS and made the field a normal member Signed-off-by: Rouven Schürch --- .../manager/impl/TemperatureControlManager.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/manager/impl/TemperatureControlManager.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/manager/impl/TemperatureControlManager.java index 18d96529ee5..c56900a0d0e 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/manager/impl/TemperatureControlManager.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/manager/impl/TemperatureControlManager.java @@ -12,12 +12,13 @@ */ package org.openhab.binding.digitalstrom.internal.lib.manager.impl; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedList; import java.util.List; +import java.util.Set; import org.openhab.binding.digitalstrom.internal.lib.climate.TemperatureControlSensorTransmitter; import org.openhab.binding.digitalstrom.internal.lib.climate.jsonresponsecontainer.impl.TemperatureControlStatus; @@ -60,7 +61,7 @@ import org.slf4j.LoggerFactory; */ public class TemperatureControlManager implements EventHandler, TemperatureControlSensorTransmitter { - private static final List SUPPORTED_EVENTS = Arrays.asList(EventNames.HEATING_CONTROL_OPERATION_MODE); + private final Set supportedEvents; private final Logger logger = LoggerFactory.getLogger(TemperatureControlManager.class); @@ -149,12 +150,14 @@ public class TemperatureControlManager implements EventHandler, TemperatureContr this.systemStateChangeListener = systemStateChangeListener; this.discovery = discovery; this.eventListener = eventListener; + this.supportedEvents = new HashSet<>(); + this.supportedEvents.add(EventNames.HEATING_CONTROL_OPERATION_MODE); checkZones(); if (eventListener != null) { if (isConfigured) { - SUPPORTED_EVENTS.add(EventNames.ZONE_SENSOR_VALUE); + supportedEvents.add(EventNames.ZONE_SENSOR_VALUE); if (systemStateChangeListener != null) { - SUPPORTED_EVENTS.add(EventNames.STATE_CHANGED); + supportedEvents.add(EventNames.STATE_CHANGED); } } eventListener.addEventHandler(this); @@ -367,12 +370,12 @@ public class TemperatureControlManager implements EventHandler, TemperatureContr @Override public List getSupportedEvents() { - return SUPPORTED_EVENTS; + return List.copyOf(supportedEvents); } @Override public boolean supportsEvent(String eventName) { - return SUPPORTED_EVENTS.contains(eventName); + return supportedEvents.contains(eventName); } @Override @@ -442,7 +445,7 @@ public class TemperatureControlManager implements EventHandler, TemperatureContr */ public void registerSystemStateChangeListener(SystemStateChangeListener systemStateChangeListener) { if (eventListener != null) { - SUPPORTED_EVENTS.add(EventNames.STATE_CHANGED); + supportedEvents.add(EventNames.STATE_CHANGED); eventListener.addSubscribe(EventNames.STATE_CHANGED); } this.systemStateChangeListener = systemStateChangeListener;