[digitalstrom] Fix initialization of temperature control devices (#16352)

* 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 <r.schuerch@gmx.ch>
This commit is contained in:
Rouven Schürch 2024-02-03 00:00:00 +01:00 committed by GitHub
parent 7671f4b9b1
commit ef7e03c1c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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<String> SUPPORTED_EVENTS = Arrays.asList(EventNames.HEATING_CONTROL_OPERATION_MODE);
private final Set<String> 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<String> 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;