diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/DiscoverComponents.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/DiscoverComponents.java index 3046847e94756..90a58ffbfe38a 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/DiscoverComponents.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/DiscoverComponents.java @@ -53,7 +53,6 @@ public class DiscoverComponents implements MqttMessageSubscriber { private final ScheduledExecutorService scheduler; private final ChannelStateUpdateListener updateListener; private final AvailabilityTracker tracker; - private final boolean newStyleChannels; protected final CompletableFuture<@Nullable Void> discoverFinishedFuture = new CompletableFuture<>(); private final Gson gson; @@ -84,7 +83,7 @@ public static interface ComponentDiscovered { */ public DiscoverComponents(ThingUID thingUID, ScheduledExecutorService scheduler, ChannelStateUpdateListener channelStateUpdateListener, AvailabilityTracker tracker, Gson gson, - Jinjava jinjava, UnitProvider unitProvider, boolean newStyleChannels) { + Jinjava jinjava, UnitProvider unitProvider) { this.thingUID = thingUID; this.scheduler = scheduler; this.updateListener = channelStateUpdateListener; @@ -92,7 +91,6 @@ public DiscoverComponents(ThingUID thingUID, ScheduledExecutorService scheduler, this.jinjava = jinjava; this.unitProvider = unitProvider; this.tracker = tracker; - this.newStyleChannels = newStyleChannels; } @Override @@ -108,7 +106,7 @@ public void processMessage(String topic, byte[] payload) { if (config.length() > 0) { try { component = ComponentFactory.createComponent(thingUID, haID, config, updateListener, tracker, scheduler, - gson, jinjava, unitProvider, newStyleChannels); + gson, jinjava, unitProvider); component.setConfigSeen(); logger.trace("Found HomeAssistant component {}", haID); diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/HaID.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/HaID.java index 7abaf4bcb151b..9b24528ac8d20 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/HaID.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/HaID.java @@ -187,19 +187,9 @@ public String toShortTopic() { * * @return group id */ - public String getGroupId(@Nullable final String uniqueId, boolean newStyleChannels) { + public String getGroupId(@Nullable final String uniqueId) { String result = uniqueId; - // newStyleChannels are auto-discovered things with openHAB >= 4.3.0 - // assuming the topic has both a node ID and an object ID, simply use - // the component type and object ID - without encoding(!) - // since the only character allowed in object IDs but not allowed in UID - // is `-`. It also doesn't need to be reversible, so it's okay to just - // collapse `-` to `_`. - if (!nodeID.isBlank() && newStyleChannels) { - return component + "_" + objectID.replace('-', '_'); - } - // the null test is only here so the compile knows, result is not null afterwards if (result == null || result.isBlank()) { StringBuilder str = new StringBuilder(); diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/AbstractComponent.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/AbstractComponent.java index 80fbb958a7d35..6b832fc767aaa 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/AbstractComponent.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/AbstractComponent.java @@ -111,7 +111,6 @@ public BigDecimal getDefaultPrecision() { protected final C channelConfiguration; protected boolean configSeen; - protected final boolean newStyleChannels; protected final String uniqueId; protected @Nullable String groupId; protected String componentId; @@ -121,14 +120,10 @@ public BigDecimal getDefaultPrecision() { * * @param componentConfiguration generic componentConfiguration with not parsed JSON config * @param clazz target configuration type - * @param newStyleChannels if new style channels should be used * @param singleChannelComponent if this component only ever has one channel, so should never be in a group - * (only if newStyleChannels is true) */ - public AbstractComponent(ComponentFactory.ComponentConfiguration componentConfiguration, Class clazz, - boolean newStyleChannels) { + public AbstractComponent(ComponentFactory.ComponentConfiguration componentConfiguration, Class clazz) { this.componentConfiguration = componentConfiguration; - this.newStyleChannels = newStyleChannels; this.channelConfigurationJson = componentConfiguration.getConfigJSON(); this.channelConfiguration = componentConfiguration.getConfig(clazz); @@ -137,18 +132,11 @@ public AbstractComponent(ComponentFactory.ComponentConfiguration componentConfig this.haID = componentConfiguration.getHaID(); String name = channelConfiguration.getName(); - if (newStyleChannels) { - // try for a simple component/group ID first; if there are conflicts - // (components of different types, but the same object id) - // we'll resolve them later - groupId = componentId = haID.objectID.replace('-', '_'); - } else if (name != null && !name.isEmpty()) { - groupId = componentId = this.haID.getGroupId(channelConfiguration.getUniqueId(), false); - } else { - groupId = null; - componentId = ""; - } - uniqueId = haID.component + "_" + haID.getGroupId(channelConfiguration.getUniqueId(), false); + // try for a simple component/group ID first; if there are conflicts + // (components of different types, but the same object id) + // we'll resolve them later + groupId = componentId = haID.objectID.replace('-', '_'); + uniqueId = haID.component + "_" + haID.getGroupId(channelConfiguration.getUniqueId()); this.configSeen = false; @@ -199,9 +187,6 @@ protected void addJsonAttributesChannel() { protected void finalizeChannels() { addJsonAttributesChannel(); - if (!newStyleChannels) { - return; - } if (channels.size() == 1) { groupId = null; channels.values().forEach(c -> c.resetUID(buildChannelUID(componentId))); @@ -214,7 +199,7 @@ protected void finalizeChannels() { } public void resolveConflict() { - if (newStyleChannels && channels.size() == 1) { + if (channels.size() == 1) { componentId = componentId + "_" + haID.component; channels.values().forEach(c -> c.resetUID(buildChannelUID(componentId))); } else { diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/AbstractRawSchemaLight.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/AbstractRawSchemaLight.java index db7241130c30a..95a5b3d3f3db7 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/AbstractRawSchemaLight.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/AbstractRawSchemaLight.java @@ -33,8 +33,8 @@ abstract class AbstractRawSchemaLight extends Light { protected ComponentChannel rawChannel; protected TextValue colorModeValue; - public AbstractRawSchemaLight(ComponentFactory.ComponentConfiguration builder, boolean newStyleChannels) { - super(builder, newStyleChannels); + public AbstractRawSchemaLight(ComponentFactory.ComponentConfiguration builder) { + super(builder); hiddenChannels.add(rawChannel = buildChannel(RAW_CHANNEL_ID, ComponentChannelType.STRING, new TextValue(), "Raw state", this).stateTopic(channelConfiguration.stateTopic) .commandTopic(channelConfiguration.commandTopic, channelConfiguration.isRetain(), diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/AlarmControlPanel.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/AlarmControlPanel.java index 2976d254867ed..4067dc2f9a705 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/AlarmControlPanel.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/AlarmControlPanel.java @@ -35,7 +35,6 @@ @NonNullByDefault public class AlarmControlPanel extends AbstractComponent { public static final String STATE_CHANNEL_ID = "state"; - public static final String STATE_CHANNEL_ID_DEPRECATED = "alarm"; public static final String SWITCH_DISARM_CHANNEL_ID = "disarm"; public static final String SWITCH_ARM_HOME_CHANNEL_ID = "armhome"; public static final String SWITCH_ARM_AWAY_CHANNEL_ID = "armaway"; @@ -93,8 +92,8 @@ static class ChannelConfiguration extends AbstractChannelConfiguration { FEATURE_ARM_VACATION, FEATURE_ARM_CUSTOM_BYPASS, FEATURE_TRIGGER); } - public AlarmControlPanel(ComponentFactory.ComponentConfiguration componentConfiguration, boolean newStyleChannels) { - super(componentConfiguration, ChannelConfiguration.class, newStyleChannels); + public AlarmControlPanel(ComponentFactory.ComponentConfiguration componentConfiguration) { + super(componentConfiguration, ChannelConfiguration.class); List stateEnum = new ArrayList(List.of(STATE_DISARMED, STATE_TRIGGERED, STATE_ARMING, STATE_DISARMING, STATE_PENDING, STATE_TRIGGERED)); @@ -124,35 +123,18 @@ public AlarmControlPanel(ComponentFactory.ComponentConfiguration componentConfig } String commandTopic = channelConfiguration.commandTopic; - TextValue value = (newStyleChannels && commandTopic != null) + TextValue value = (commandTopic != null) ? new TextValue(stateEnum.toArray(new String[0]), commandEnum.toArray(new String[0])) : new TextValue(stateEnum.toArray(new String[0])); - var builder = buildChannel(newStyleChannels ? STATE_CHANNEL_ID : STATE_CHANNEL_ID_DEPRECATED, - ComponentChannelType.STRING, value, getName(), componentConfiguration.getUpdateListener()) + var builder = buildChannel(STATE_CHANNEL_ID, ComponentChannelType.STRING, value, getName(), + componentConfiguration.getUpdateListener()) .stateTopic(channelConfiguration.stateTopic, channelConfiguration.getValueTemplate()); - if (newStyleChannels && commandTopic != null) { + if (commandTopic != null) { builder.commandTopic(commandTopic, channelConfiguration.isRetain(), channelConfiguration.getQos()); } builder.build(); - if (!newStyleChannels && commandTopic != null) { - buildChannel(SWITCH_DISARM_CHANNEL_ID, ComponentChannelType.STRING, - new TextValue(new String[] { channelConfiguration.payloadDisarm }), getName(), - componentConfiguration.getUpdateListener()) - .commandTopic(commandTopic, channelConfiguration.isRetain(), channelConfiguration.getQos()).build(); - - buildChannel(SWITCH_ARM_HOME_CHANNEL_ID, ComponentChannelType.STRING, - new TextValue(new String[] { channelConfiguration.payloadArmHome }), getName(), - componentConfiguration.getUpdateListener()) - .commandTopic(commandTopic, channelConfiguration.isRetain(), channelConfiguration.getQos()).build(); - - buildChannel(SWITCH_ARM_AWAY_CHANNEL_ID, ComponentChannelType.STRING, - new TextValue(new String[] { channelConfiguration.payloadArmAway }), getName(), - componentConfiguration.getUpdateListener()) - .commandTopic(commandTopic, channelConfiguration.isRetain(), channelConfiguration.getQos()).build(); - } - finalizeChannels(); } } diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/BinarySensor.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/BinarySensor.java index c840d36d5aea8..52192326c70ec 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/BinarySensor.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/BinarySensor.java @@ -59,8 +59,8 @@ static class ChannelConfiguration extends AbstractChannelConfiguration { protected String payloadOff = "OFF"; } - public BinarySensor(ComponentFactory.ComponentConfiguration componentConfiguration, boolean newStyleChannels) { - super(componentConfiguration, ChannelConfiguration.class, newStyleChannels); + public BinarySensor(ComponentFactory.ComponentConfiguration componentConfiguration) { + super(componentConfiguration, ChannelConfiguration.class); OnOffValue value = new OnOffValue(channelConfiguration.payloadOn, channelConfiguration.payloadOff); diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Button.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Button.java index 7ac20139deb8e..39c896b120647 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Button.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Button.java @@ -47,8 +47,8 @@ static class ChannelConfiguration extends AbstractChannelConfiguration { protected String payloadPress = "PRESS"; } - public Button(ComponentFactory.ComponentConfiguration componentConfiguration, boolean newStyleChannels) { - super(componentConfiguration, ChannelConfiguration.class, newStyleChannels); + public Button(ComponentFactory.ComponentConfiguration componentConfiguration) { + super(componentConfiguration, ChannelConfiguration.class); TextValue value = new TextValue(new String[] { channelConfiguration.payloadPress }); diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Camera.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Camera.java index 94ae6c3a342e6..02660dd759044 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Camera.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Camera.java @@ -39,8 +39,8 @@ static class ChannelConfiguration extends AbstractChannelConfiguration { protected String topic = ""; } - public Camera(ComponentFactory.ComponentConfiguration componentConfiguration, boolean newStyleChannels) { - super(componentConfiguration, ChannelConfiguration.class, newStyleChannels); + public Camera(ComponentFactory.ComponentConfiguration componentConfiguration) { + super(componentConfiguration, ChannelConfiguration.class); ImageValue value = new ImageValue(); diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Climate.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Climate.java index 6396b1e44b0a0..bccc4865c457c 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Climate.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Climate.java @@ -49,12 +49,9 @@ public class Climate extends AbstractComponent { public static final String ACTION_CH_ID = "action"; public static final String AUX_CH_ID = "aux"; public static final String AWAY_MODE_CH_ID = "away-mode"; - public static final String AWAY_MODE_CH_ID_DEPRECATED = "awayMode"; public static final String CURRENT_HUMIDITY_CH_ID = "current-humidity"; public static final String CURRENT_TEMPERATURE_CH_ID = "current-temperature"; - public static final String CURRENT_TEMPERATURE_CH_ID_DEPRECATED = "currentTemperature"; public static final String FAN_MODE_CH_ID = "fan-mode"; - public static final String FAN_MODE_CH_ID_DEPRECATED = "fanMode"; public static final String HOLD_CH_ID = "hold"; public static final String MODE_CH_ID = "mode"; public static final String PRESET_MODE_CH_ID = "preset-mode"; @@ -62,9 +59,7 @@ public class Climate extends AbstractComponent { public static final String TARGET_HUMIDITY_CH_ID = "target-humidity"; public static final String TEMPERATURE_CH_ID = "temperature"; public static final String TEMPERATURE_HIGH_CH_ID = "temperature-high"; - public static final String TEMPERATURE_HIGH_CH_ID_DEPRECATED = "temperatureHigh"; public static final String TEMPERATURE_LOW_CH_ID = "temperature-low"; - public static final String TEMPERATURE_LOW_CH_ID_DEPRECATED = "temperatureLow"; public static final String POWER_CH_ID = "power"; private static final String ACTION_OFF = "off"; @@ -224,8 +219,8 @@ static class ChannelConfiguration extends AbstractChannelConfiguration { protected Boolean sendIfOff = true; } - public Climate(ComponentFactory.ComponentConfiguration componentConfiguration, boolean newStyleChannels) { - super(componentConfiguration, ChannelConfiguration.class, newStyleChannels); + public Climate(ComponentFactory.ComponentConfiguration componentConfiguration) { + super(componentConfiguration, ChannelConfiguration.class); TemperatureUnit temperatureUnit = channelConfiguration.temperatureUnit; if (channelConfiguration.temperatureUnit == null) { @@ -250,8 +245,7 @@ public Climate(ComponentFactory.ComponentConfiguration componentConfiguration, b channelConfiguration.auxCommandTopic, channelConfiguration.auxStateTemplate, channelConfiguration.auxStateTopic, commandFilter); - buildOptionalChannel(newStyleChannels ? AWAY_MODE_CH_ID : AWAY_MODE_CH_ID_DEPRECATED, - ComponentChannelType.SWITCH, new OnOffValue(), updateListener, null, + buildOptionalChannel(AWAY_MODE_CH_ID, ComponentChannelType.SWITCH, new OnOffValue(), updateListener, null, channelConfiguration.awayModeCommandTopic, channelConfiguration.awayModeStateTemplate, channelConfiguration.awayModeStateTopic, commandFilter); @@ -259,12 +253,12 @@ ComponentChannelType.SWITCH, new OnOffValue(), updateListener, null, new NumberValue(new BigDecimal(0), new BigDecimal(100), null, Units.PERCENT), updateListener, null, null, channelConfiguration.currentHumidityTemplate, channelConfiguration.currentHumidityTopic, null); - buildOptionalChannel(newStyleChannels ? CURRENT_TEMPERATURE_CH_ID : CURRENT_TEMPERATURE_CH_ID_DEPRECATED, - ComponentChannelType.TEMPERATURE, new NumberValue(null, null, precision, temperatureUnit.getUnit()), - updateListener, null, null, channelConfiguration.currentTemperatureTemplate, - channelConfiguration.currentTemperatureTopic, commandFilter); + buildOptionalChannel(CURRENT_TEMPERATURE_CH_ID, ComponentChannelType.TEMPERATURE, + new NumberValue(null, null, precision, temperatureUnit.getUnit()), updateListener, null, null, + channelConfiguration.currentTemperatureTemplate, channelConfiguration.currentTemperatureTopic, + commandFilter); - buildOptionalChannel(newStyleChannels ? FAN_MODE_CH_ID : FAN_MODE_CH_ID_DEPRECATED, ComponentChannelType.STRING, + buildOptionalChannel(FAN_MODE_CH_ID, ComponentChannelType.STRING, new TextValue(channelConfiguration.fanModes.toArray(new String[0])), updateListener, channelConfiguration.fanModeCommandTemplate, channelConfiguration.fanModeCommandTopic, channelConfiguration.fanModeStateTemplate, channelConfiguration.fanModeStateTopic, commandFilter); @@ -306,16 +300,14 @@ ComponentChannelType.TEMPERATURE, new NumberValue(null, null, precision, tempera channelConfiguration.temperatureCommandTopic, channelConfiguration.temperatureStateTemplate, channelConfiguration.temperatureStateTopic, commandFilter); - buildOptionalChannel(newStyleChannels ? TEMPERATURE_HIGH_CH_ID : TEMPERATURE_HIGH_CH_ID_DEPRECATED, - ComponentChannelType.TEMPERATURE, + buildOptionalChannel(TEMPERATURE_HIGH_CH_ID, ComponentChannelType.TEMPERATURE, new NumberValue(channelConfiguration.minTemp, channelConfiguration.maxTemp, channelConfiguration.tempStep, temperatureUnit.getUnit()), updateListener, channelConfiguration.temperatureHighCommandTemplate, channelConfiguration.temperatureHighCommandTopic, channelConfiguration.temperatureHighStateTemplate, channelConfiguration.temperatureHighStateTopic, commandFilter); - buildOptionalChannel(newStyleChannels ? TEMPERATURE_LOW_CH_ID : TEMPERATURE_LOW_CH_ID_DEPRECATED, - ComponentChannelType.TEMPERATURE, + buildOptionalChannel(TEMPERATURE_LOW_CH_ID, ComponentChannelType.TEMPERATURE, new NumberValue(channelConfiguration.minTemp, channelConfiguration.maxTemp, channelConfiguration.tempStep, temperatureUnit.getUnit()), updateListener, channelConfiguration.temperatureLowCommandTemplate, diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/ComponentFactory.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/ComponentFactory.java index a6d4e8194872f..1e0a1edd77a74 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/ComponentFactory.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/ComponentFactory.java @@ -48,59 +48,58 @@ public class ComponentFactory { */ public static AbstractComponent createComponent(ThingUID thingUID, HaID haID, String channelConfigurationJSON, ChannelStateUpdateListener updateListener, AvailabilityTracker tracker, ScheduledExecutorService scheduler, - Gson gson, Jinjava jinjava, UnitProvider unitProvider, boolean newStyleChannels) - throws ConfigurationException { + Gson gson, Jinjava jinjava, UnitProvider unitProvider) throws ConfigurationException { ComponentConfiguration componentConfiguration = new ComponentConfiguration(thingUID, haID, channelConfigurationJSON, gson, jinjava, updateListener, tracker, scheduler, unitProvider); switch (haID.component) { case "alarm_control_panel": - return new AlarmControlPanel(componentConfiguration, newStyleChannels); + return new AlarmControlPanel(componentConfiguration); case "binary_sensor": - return new BinarySensor(componentConfiguration, newStyleChannels); + return new BinarySensor(componentConfiguration); case "button": - return new Button(componentConfiguration, newStyleChannels); + return new Button(componentConfiguration); case "camera": - return new Camera(componentConfiguration, newStyleChannels); + return new Camera(componentConfiguration); case "climate": - return new Climate(componentConfiguration, newStyleChannels); + return new Climate(componentConfiguration); case "cover": - return new Cover(componentConfiguration, newStyleChannels); + return new Cover(componentConfiguration); case "device_automation": - return new DeviceTrigger(componentConfiguration, newStyleChannels); + return new DeviceTrigger(componentConfiguration); case "device_tracker": - return new DeviceTracker(componentConfiguration, newStyleChannels); + return new DeviceTracker(componentConfiguration); case "event": - return new Event(componentConfiguration, newStyleChannels); + return new Event(componentConfiguration); case "fan": - return new Fan(componentConfiguration, newStyleChannels); + return new Fan(componentConfiguration); case "humidifier": - return new Humidifier(componentConfiguration, newStyleChannels); + return new Humidifier(componentConfiguration); case "light": - return Light.create(componentConfiguration, newStyleChannels); + return Light.create(componentConfiguration); case "lock": - return new Lock(componentConfiguration, newStyleChannels); + return new Lock(componentConfiguration); case "number": - return new Number(componentConfiguration, newStyleChannels); + return new Number(componentConfiguration); case "scene": - return new Scene(componentConfiguration, newStyleChannels); + return new Scene(componentConfiguration); case "select": - return new Select(componentConfiguration, newStyleChannels); + return new Select(componentConfiguration); case "sensor": - return new Sensor(componentConfiguration, newStyleChannels); + return new Sensor(componentConfiguration); case "switch": - return new Switch(componentConfiguration, newStyleChannels); + return new Switch(componentConfiguration); case "tag": - return new Tag(componentConfiguration, newStyleChannels); + return new Tag(componentConfiguration); case "text": - return new Text(componentConfiguration, newStyleChannels); + return new Text(componentConfiguration); case "update": - return new Update(componentConfiguration, newStyleChannels); + return new Update(componentConfiguration); case "vacuum": - return new Vacuum(componentConfiguration, newStyleChannels); + return new Vacuum(componentConfiguration); case "valve": - return new Valve(componentConfiguration, newStyleChannels); + return new Valve(componentConfiguration); case "water_heater": - return new WaterHeater(componentConfiguration, newStyleChannels); + return new WaterHeater(componentConfiguration); default: throw new UnsupportedComponentException("Component '" + haID + "' is unsupported!"); } diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Cover.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Cover.java index 2aad521fec43a..b0f2ecc53ae0a 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Cover.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Cover.java @@ -88,8 +88,8 @@ static class ChannelConfiguration extends AbstractChannelConfiguration { @Nullable ComponentChannel stateChannel = null; - public Cover(ComponentFactory.ComponentConfiguration componentConfiguration, boolean newStyleChannels) { - super(componentConfiguration, ChannelConfiguration.class, newStyleChannels); + public Cover(ComponentFactory.ComponentConfiguration componentConfiguration) { + super(componentConfiguration, ChannelConfiguration.class); boolean optimistic = false; Boolean localOptimistic = channelConfiguration.optimistic; diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/DefaultSchemaLight.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/DefaultSchemaLight.java index 8a4e4a019a49e..b603d995f86db 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/DefaultSchemaLight.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/DefaultSchemaLight.java @@ -55,17 +55,16 @@ public class DefaultSchemaLight extends Light { protected @Nullable ComponentChannel rgbChannel; protected @Nullable ComponentChannel xyChannel; - public DefaultSchemaLight(ComponentFactory.ComponentConfiguration builder, boolean newStyleChannels) { - super(builder, newStyleChannels); + public DefaultSchemaLight(ComponentFactory.ComponentConfiguration builder) { + super(builder); } @Override protected void buildChannels() { AutoUpdatePolicy autoUpdatePolicy = optimistic ? AutoUpdatePolicy.RECOMMEND : null; ComponentChannel localOnOffChannel; - localOnOffChannel = onOffChannel = buildChannel( - newStyleChannels ? SWITCH_CHANNEL_ID : SWITCH_CHANNEL_ID_DEPRECATED, ComponentChannelType.SWITCH, - onOffValue, "On/Off State", this) + localOnOffChannel = onOffChannel = buildChannel(SWITCH_CHANNEL_ID, ComponentChannelType.SWITCH, onOffValue, + "On/Off State", this) .stateTopic(channelConfiguration.stateTopic, channelConfiguration.stateValueTemplate) .commandTopic(channelConfiguration.commandTopic, channelConfiguration.isRetain(), channelConfiguration.getQos()) @@ -92,15 +91,14 @@ protected void buildChannels() { } if (channelConfiguration.colorModeStateTopic != null) { - buildChannel(newStyleChannels ? COLOR_MODE_CHANNEL_ID : COLOR_MODE_CHANNEL_ID_DEPRECATED, - ComponentChannelType.STRING, new TextValue(), "Current color mode", this) + buildChannel(COLOR_MODE_CHANNEL_ID, ComponentChannelType.STRING, new TextValue(), "Current color mode", + this) .stateTopic(channelConfiguration.colorModeStateTopic, channelConfiguration.colorModeValueTemplate) .inferOptimistic(channelConfiguration.optimistic).build(); } if (channelConfiguration.colorTempStateTopic != null || channelConfiguration.colorTempCommandTopic != null) { - buildChannel(newStyleChannels ? COLOR_TEMP_CHANNEL_ID : COLOR_TEMP_CHANNEL_ID_DEPRECATED, - ComponentChannelType.NUMBER, colorTempValue, "Color Temperature", this) + buildChannel(COLOR_TEMP_CHANNEL_ID, ComponentChannelType.NUMBER, colorTempValue, "Color Temperature", this) .stateTopic(channelConfiguration.colorTempStateTopic, channelConfiguration.colorTempValueTemplate) .commandTopic(channelConfiguration.colorTempCommandTopic, channelConfiguration.isRetain(), channelConfiguration.getQos()) @@ -180,7 +178,7 @@ ComponentChannelType.STRING, new TextValue(), "Current color mode", this) hiddenChannels.add(localOnOffChannel); channels.put(BRIGHTNESS_CHANNEL_ID, localBrightnessChannel); } else { - channels.put(newStyleChannels ? SWITCH_CHANNEL_ID : SWITCH_CHANNEL_ID_DEPRECATED, localOnOffChannel); + channels.put(SWITCH_CHANNEL_ID, localOnOffChannel); } } @@ -329,8 +327,7 @@ public void updateChannelState(ChannelUID channel, State state) { } else { listener.updateChannelState(primaryChannelUID, state); } - } else if (id.equals(newStyleChannels ? COLOR_TEMP_CHANNEL_ID : COLOR_TEMP_CHANNEL_ID_DEPRECATED) - || channel.getIdWithoutGroup().equals(EFFECT_CHANNEL_ID)) { + } else if (id.equals(COLOR_TEMP_CHANNEL_ID) || channel.getIdWithoutGroup().equals(EFFECT_CHANNEL_ID)) { // Real channels; pass through listener.updateChannelState(channel, state); } else if (id.equals(HS_CHANNEL_ID) || id.equals(XY_CHANNEL_ID)) { diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/DeviceTracker.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/DeviceTracker.java index 70b47010ba89a..982bb46d17e78 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/DeviceTracker.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/DeviceTracker.java @@ -98,8 +98,8 @@ static class JSONAttributes { private final LocationValue locationValue = new LocationValue(); private final @Nullable ComponentChannel homeChannel, locationChannel, accuracyChannel; - public DeviceTracker(ComponentFactory.ComponentConfiguration componentConfiguration, boolean newStyleChannels) { - super(componentConfiguration, ChannelConfiguration.class, newStyleChannels); + public DeviceTracker(ComponentFactory.ComponentConfiguration componentConfiguration) { + super(componentConfiguration, ChannelConfiguration.class); this.channelStateUpdateListener = componentConfiguration.getUpdateListener(); if (channelConfiguration.stateTopic == null && channelConfiguration.getJsonAttributesTopic() == null) { diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/DeviceTrigger.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/DeviceTrigger.java index 68723b765a9d5..6ad063e82b23e 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/DeviceTrigger.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/DeviceTrigger.java @@ -59,8 +59,8 @@ public String getSubtype() { } } - public DeviceTrigger(ComponentFactory.ComponentConfiguration componentConfiguration, boolean newStyleChannels) { - super(componentConfiguration, ChannelConfiguration.class, newStyleChannels); + public DeviceTrigger(ComponentFactory.ComponentConfiguration componentConfiguration) { + super(componentConfiguration, ChannelConfiguration.class); if (!"trigger".equals(channelConfiguration.automationType)) { throw new ConfigurationException("Component:DeviceTrigger must have automation_type 'trigger'"); @@ -72,13 +72,11 @@ public DeviceTrigger(ComponentFactory.ComponentConfiguration componentConfigurat throw new ConfigurationException("Component:DeviceTrigger must have a subtype"); } - if (newStyleChannels) { - // Name the channel after the subtype, not the component ID - // So that we only end up with a single channel for all possible events - // for a single button (subtype is the button, type is type of press) - componentId = channelConfiguration.subtype; - groupId = null; - } + // Name the channel after the subtype, not the component ID + // So that we only end up with a single channel for all possible events + // for a single button (subtype is the button, type is type of press) + componentId = channelConfiguration.subtype; + groupId = null; TextValue value; String payload = channelConfiguration.payload; diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Event.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Event.java index feda65bccf86f..ead8411b1f274 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Event.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Event.java @@ -54,8 +54,8 @@ public static class ChannelConfiguration extends AbstractChannelConfiguration { private final HomeAssistantChannelTransformation transformation; - public Event(ComponentFactory.ComponentConfiguration componentConfiguration, boolean newStyleChannels) { - super(componentConfiguration, ChannelConfiguration.class, newStyleChannels); + public Event(ComponentFactory.ComponentConfiguration componentConfiguration) { + super(componentConfiguration, ChannelConfiguration.class); transformation = new HomeAssistantChannelTransformation(getJinjava(), this, ""); diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Fan.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Fan.java index 99394e0886003..8928217165b5c 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Fan.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Fan.java @@ -44,7 +44,6 @@ @NonNullByDefault public class Fan extends AbstractComponent implements ChannelStateUpdateListener { public static final String SWITCH_CHANNEL_ID = "switch"; - public static final String SWITCH_CHANNEL_ID_DEPRECATED = "fan"; public static final String SPEED_CHANNEL_ID = "speed"; public static final String PRESET_MODE_CHANNEL_ID = "preset-mode"; public static final String OSCILLATION_CHANNEL_ID = "oscillation"; @@ -131,16 +130,16 @@ static class ChannelConfiguration extends AbstractChannelConfiguration { private final ComponentChannel primaryChannel; private final ChannelStateUpdateListener channelStateUpdateListener; - public Fan(ComponentFactory.ComponentConfiguration componentConfiguration, boolean newStyleChannels) { - super(componentConfiguration, ChannelConfiguration.class, newStyleChannels); + public Fan(ComponentFactory.ComponentConfiguration componentConfiguration) { + super(componentConfiguration, ChannelConfiguration.class); this.channelStateUpdateListener = componentConfiguration.getUpdateListener(); onOffValue = new OnOffValue(channelConfiguration.payloadOn, channelConfiguration.payloadOff); ChannelStateUpdateListener onOffListener = channelConfiguration.percentageCommandTopic == null ? componentConfiguration.getUpdateListener() : this; - onOffChannel = buildChannel(newStyleChannels ? SWITCH_CHANNEL_ID : SWITCH_CHANNEL_ID_DEPRECATED, - ComponentChannelType.SWITCH, onOffValue, "On/Off State", onOffListener) + onOffChannel = buildChannel(SWITCH_CHANNEL_ID, ComponentChannelType.SWITCH, onOffValue, "On/Off State", + onOffListener) .stateTopic(channelConfiguration.stateTopic, channelConfiguration.stateValueTemplate) .commandTopic(channelConfiguration.commandTopic, channelConfiguration.isRetain(), channelConfiguration.getQos(), channelConfiguration.commandTemplate) diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Humidifier.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Humidifier.java index cedbbde975a39..111f4f88ec8be 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Humidifier.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Humidifier.java @@ -108,8 +108,8 @@ static class ChannelConfiguration extends AbstractChannelConfiguration { protected @Nullable List modes; } - public Humidifier(ComponentFactory.ComponentConfiguration componentConfiguration, boolean newStyleChannels) { - super(componentConfiguration, ChannelConfiguration.class, newStyleChannels); + public Humidifier(ComponentFactory.ComponentConfiguration componentConfiguration) { + super(componentConfiguration, ChannelConfiguration.class); if (!PLATFORM_HUMIDIFIER.equals(channelConfiguration.platform)) { throw new ConfigurationException("platform must be " + PLATFORM_HUMIDIFIER); diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/JSONSchemaLight.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/JSONSchemaLight.java index d21651a8f557a..f446d19fb0e1f 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/JSONSchemaLight.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/JSONSchemaLight.java @@ -76,8 +76,8 @@ protected static class Color { protected @Nullable Integer transition; } - public JSONSchemaLight(ComponentFactory.ComponentConfiguration builder, boolean newStyleChannels) { - super(builder, newStyleChannels); + public JSONSchemaLight(ComponentFactory.ComponentConfiguration builder) { + super(builder); } @Override @@ -91,17 +91,15 @@ protected void buildChannels() { } if (supportedColorModes.contains(LightColorMode.COLOR_MODE_COLOR_TEMP)) { - colorTempChannel = buildChannel( - newStyleChannels ? COLOR_TEMP_CHANNEL_ID : COLOR_TEMP_CHANNEL_ID_DEPRECATED, - ComponentChannelType.NUMBER, colorTempValue, "Color Temperature", this) - .commandTopic(DUMMY_TOPIC, true, 1).commandFilter(command -> handleColorTempCommand(command)) + colorTempChannel = buildChannel(COLOR_TEMP_CHANNEL_ID, ComponentChannelType.NUMBER, colorTempValue, + "Color Temperature", this).commandTopic(DUMMY_TOPIC, true, 1) + .commandFilter(command -> handleColorTempCommand(command)) .withAutoUpdatePolicy(autoUpdatePolicy).build(); if (hasColorChannel) { colorModeValue = new TextValue( supportedColorModes.stream().map(LightColorMode::serializedName).toArray(String[]::new)); - buildChannel(newStyleChannels ? COLOR_MODE_CHANNEL_ID : COLOR_MODE_CHANNEL_ID_DEPRECATED, - ComponentChannelType.STRING, colorModeValue, "Color Mode", this) + buildChannel(COLOR_MODE_CHANNEL_ID, ComponentChannelType.STRING, colorModeValue, "Color Mode", this) .withAutoUpdatePolicy(autoUpdatePolicy).isAdvanced(true).build(); } @@ -117,9 +115,9 @@ protected void buildChannels() { "Brightness", this).commandTopic(DUMMY_TOPIC, true, 1).commandFilter(this::handleCommand) .withAutoUpdatePolicy(autoUpdatePolicy).build(); } else { - onOffChannel = buildChannel(newStyleChannels ? SWITCH_CHANNEL_ID : SWITCH_CHANNEL_ID_DEPRECATED, - ComponentChannelType.SWITCH, onOffValue, "On/Off State", this).commandTopic(DUMMY_TOPIC, true, 1) - .commandFilter(this::handleCommand).withAutoUpdatePolicy(autoUpdatePolicy).build(); + onOffChannel = buildChannel(SWITCH_CHANNEL_ID, ComponentChannelType.SWITCH, onOffValue, "On/Off State", + this).commandTopic(DUMMY_TOPIC, true, 1).commandFilter(this::handleCommand) + .withAutoUpdatePolicy(autoUpdatePolicy).build(); } if (effectValue != null) { @@ -314,8 +312,7 @@ public void updateChannelState(ChannelUID channel, State state) { } else { colorTempValue .update(new QuantityType(Objects.requireNonNull(jsonState.colorTemp), Units.MIRED)); - listener.updateChannelState(buildChannelUID( - newStyleChannels ? COLOR_TEMP_CHANNEL_ID : COLOR_TEMP_CHANNEL_ID_DEPRECATED), + listener.updateChannelState(buildChannelUID(COLOR_TEMP_CHANNEL_ID), colorTempValue.getChannelState()); // Populate the color channel (if there is one) to match the color temperature. @@ -342,8 +339,7 @@ public void updateChannelState(ChannelUID channel, State state) { if (colorTempChannel != null) { double kelvin = ColorUtil.xyToKelvin(xy); colorTempValue.update(new QuantityType(kelvin, Units.KELVIN)); - listener.updateChannelState(buildChannelUID( - newStyleChannels ? COLOR_TEMP_CHANNEL_ID : COLOR_TEMP_CHANNEL_ID_DEPRECATED), + listener.updateChannelState(buildChannelUID(COLOR_TEMP_CHANNEL_ID), colorTempValue.getChannelState()); } } @@ -378,9 +374,7 @@ public void updateChannelState(ChannelUID channel, State state) { final double[] xy = ColorUtil.hsbToXY(colorState); double kelvin = ColorUtil.xyToKelvin(new double[] { xy[0], xy[1] }); colorTempValue.update(new QuantityType(kelvin, Units.KELVIN)); - listener.updateChannelState( - buildChannelUID( - newStyleChannels ? COLOR_TEMP_CHANNEL_ID : COLOR_TEMP_CHANNEL_ID_DEPRECATED), + listener.updateChannelState(buildChannelUID(COLOR_TEMP_CHANNEL_ID), colorTempValue.getChannelState()); } @@ -389,9 +383,7 @@ public void updateChannelState(ChannelUID channel, State state) { // https://github.com/home-assistant/core/blob/4f965f0eca09f0d12ae1c98c6786054063a36b44/homeassistant/components/mqtt/light/schema_json.py#L258 if (jsonState.colorTemp != null) { colorTempValue.update(new QuantityType(Objects.requireNonNull(jsonState.colorTemp), Units.MIRED)); - listener.updateChannelState( - buildChannelUID( - newStyleChannels ? COLOR_TEMP_CHANNEL_ID : COLOR_TEMP_CHANNEL_ID_DEPRECATED), + listener.updateChannelState(buildChannelUID(COLOR_TEMP_CHANNEL_ID), colorTempValue.getChannelState()); colorModeValue.update(new StringType(LightColorMode.COLOR_MODE_COLOR_TEMP.serializedName())); @@ -419,9 +411,7 @@ public void updateChannelState(ChannelUID channel, State state) { logger.warn("Invalid color value for {}", getHaID()); } - listener.updateChannelState( - buildChannelUID(newStyleChannels ? COLOR_MODE_CHANNEL_ID : COLOR_MODE_CHANNEL_ID_DEPRECATED), - colorModeValue.getChannelState()); + listener.updateChannelState(buildChannelUID(COLOR_MODE_CHANNEL_ID), colorModeValue.getChannelState()); if (localColorChannel != null) { listener.updateChannelState(localColorChannel.getChannel().getUID(), colorValue.getChannelState()); diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Light.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Light.java index d704679adef2b..6fd24adff89ea 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Light.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Light.java @@ -56,12 +56,9 @@ public abstract class Light extends AbstractComponent handleCommand(command)).withAutoUpdatePolicy(autoUpdatePolicy).build(); } else { - onOffChannel = buildChannel(newStyleChannels ? SWITCH_CHANNEL_ID : SWITCH_CHANNEL_ID_DEPRECATED, - ComponentChannelType.SWITCH, onOffValue, "On/Off State", this).commandTopic(DUMMY_TOPIC, true, 1) - .commandFilter(command -> handleCommand(command)).withAutoUpdatePolicy(autoUpdatePolicy).build(); + onOffChannel = buildChannel(SWITCH_CHANNEL_ID, ComponentChannelType.SWITCH, onOffValue, "On/Off State", + this).commandTopic(DUMMY_TOPIC, true, 1).commandFilter(command -> handleCommand(command)) + .withAutoUpdatePolicy(autoUpdatePolicy).build(); } if (channelConfiguration.colorTempTemplate != null) { - buildChannel(newStyleChannels ? COLOR_TEMP_CHANNEL_ID : COLOR_TEMP_CHANNEL_ID_DEPRECATED, - ComponentChannelType.NUMBER, colorTempValue, "Color Temperature", this) + buildChannel(COLOR_TEMP_CHANNEL_ID, ComponentChannelType.NUMBER, colorTempValue, "Color Temperature", this) .commandTopic(DUMMY_TOPIC, true, 1).commandFilter(command -> handleColorTempCommand(command)) .withAutoUpdatePolicy(autoUpdatePolicy).build(); } @@ -285,9 +284,7 @@ public void updateChannelState(ChannelUID channel, State state) { } else { colorTempValue.update(new QuantityType(mireds, Units.MIRED)); } - listener.updateChannelState( - buildChannelUID(newStyleChannels ? COLOR_TEMP_CHANNEL_ID : COLOR_TEMP_CHANNEL_ID_DEPRECATED), - colorTempValue.getChannelState()); + listener.updateChannelState(buildChannelUID(COLOR_TEMP_CHANNEL_ID), colorTempValue.getChannelState()); } } diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Text.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Text.java index 690123b500787..74b5342689988 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Text.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Text.java @@ -54,8 +54,8 @@ static class ChannelConfiguration extends AbstractChannelConfiguration { protected String mode = MODE_TEXT; // Presumably for a password, it should mask any controls in the UI } - public Text(ComponentFactory.ComponentConfiguration componentConfiguration, boolean newStyleChannels) { - super(componentConfiguration, ChannelConfiguration.class, newStyleChannels); + public Text(ComponentFactory.ComponentConfiguration componentConfiguration) { + super(componentConfiguration, ChannelConfiguration.class); TextValue value = new TextValue(); diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Update.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Update.java index 07aeb74f2d767..6e982f67262fd 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Update.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Update.java @@ -143,8 +143,8 @@ public interface ReleaseStateListener { private ReleaseState state = new ReleaseState(); private @Nullable ReleaseStateListener listener = null; - public Update(ComponentFactory.ComponentConfiguration componentConfiguration, boolean newStyleChannels) { - super(componentConfiguration, ChannelConfiguration.class, newStyleChannels); + public Update(ComponentFactory.ComponentConfiguration componentConfiguration) { + super(componentConfiguration, ChannelConfiguration.class); TextValue value = new TextValue(); String commandTopic = channelConfiguration.commandTopic; diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Vacuum.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Vacuum.java index 502601c0e006e..3dd1d40c0c409 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Vacuum.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Vacuum.java @@ -58,13 +58,9 @@ public class Vacuum extends AbstractComponent { public static final String COMMAND_CH_ID = "command"; public static final String FAN_SPEED_CH_ID = "fan-speed"; - public static final String FAN_SPEED_CH_ID_DEPRECATED = "fanSpeed"; public static final String CUSTOM_COMMAND_CH_ID = "custom-command"; - public static final String CUSTOM_COMMAND_CH_ID_DEPRECATED = "customCommand"; public static final String BATTERY_LEVEL_CH_ID = "battery-level"; - public static final String BATTERY_LEVEL_CH_ID_DEPRECATED = "batteryLevel"; public static final String JSON_ATTRIBUTES_CH_ID = "json-attributes"; - public static final String JSON_ATTRIBUTES_CH_ID_DEPRECATED = "jsonAttributes"; public static final String STATE_CH_ID = "state"; private static final String STATE_TEMPLATE = "{{ value_json.state }}"; @@ -122,8 +118,8 @@ static class ChannelConfiguration extends AbstractChannelConfiguration { * * @param componentConfiguration generic componentConfiguration with not parsed JSON config */ - public Vacuum(ComponentFactory.ComponentConfiguration componentConfiguration, boolean newStyleChannels) { - super(componentConfiguration, ChannelConfiguration.class, newStyleChannels); + public Vacuum(ComponentFactory.ComponentConfiguration componentConfiguration) { + super(componentConfiguration, ChannelConfiguration.class); final ChannelStateUpdateListener updateListener = componentConfiguration.getUpdateListener(); final var supportedFeatures = channelConfiguration.supportedFeatures; @@ -137,7 +133,7 @@ public Vacuum(ComponentFactory.ComponentConfiguration componentConfiguration, bo addPayloadToList(supportedFeatures, FEATURE_PAUSE, channelConfiguration.payloadPause, commands); buildOptionalChannel(COMMAND_CH_ID, ComponentChannelType.STRING, new TextValue(commands.toArray(new String[0])), - updateListener, null, channelConfiguration.commandTopic, null, null); + updateListener, null, channelConfiguration.commandTopic, null, null, "Command"); final var fanSpeedList = channelConfiguration.fanSpeedList; if (supportedFeatures.contains(FEATURE_FAN_SPEED) && fanSpeedList != null && !fanSpeedList.isEmpty()) { @@ -147,21 +143,18 @@ public Vacuum(ComponentFactory.ComponentConfiguration componentConfiguration, bo } var fanSpeedValue = new TextValue(fanSpeedList.toArray(new String[0]), fanSpeedCommandList); if (supportedFeatures.contains(FEATURE_STATUS)) { - buildOptionalChannel(newStyleChannels ? FAN_SPEED_CH_ID : FAN_SPEED_CH_ID_DEPRECATED, - ComponentChannelType.STRING, fanSpeedValue, updateListener, null, + buildOptionalChannel(FAN_SPEED_CH_ID, ComponentChannelType.STRING, fanSpeedValue, updateListener, null, channelConfiguration.setFanSpeedTopic, "{{ value_json.fan_speed }}", - channelConfiguration.stateTopic); + channelConfiguration.stateTopic, "Fan Speed"); } else { - buildOptionalChannel(newStyleChannels ? FAN_SPEED_CH_ID : FAN_SPEED_CH_ID_DEPRECATED, - ComponentChannelType.STRING, fanSpeedValue, updateListener, null, - channelConfiguration.setFanSpeedTopic, null, null); + buildOptionalChannel(FAN_SPEED_CH_ID, ComponentChannelType.STRING, fanSpeedValue, updateListener, null, + channelConfiguration.setFanSpeedTopic, null, null, "Fan Speed"); } } if (supportedFeatures.contains(FEATURE_SEND_COMMAND)) { - buildOptionalChannel(newStyleChannels ? CUSTOM_COMMAND_CH_ID : CUSTOM_COMMAND_CH_ID_DEPRECATED, - ComponentChannelType.STRING, new TextValue(), updateListener, null, - channelConfiguration.sendCommandTopic, null, null); + buildOptionalChannel(CUSTOM_COMMAND_CH_ID, ComponentChannelType.STRING, new TextValue(), updateListener, + null, channelConfiguration.sendCommandTopic, null, null, "Custom Command"); } if (supportedFeatures.contains(FEATURE_STATUS)) { @@ -169,32 +162,24 @@ ComponentChannelType.STRING, new TextValue(), updateListener, null, buildOptionalChannel(STATE_CH_ID, ComponentChannelType.STRING, new TextValue(new String[] { STATE_CLEANING, STATE_DOCKED, STATE_PAUSED, STATE_IDLE, STATE_RETURNING, STATE_ERROR }), - updateListener, null, null, STATE_TEMPLATE, channelConfiguration.stateTopic); + updateListener, null, null, STATE_TEMPLATE, channelConfiguration.stateTopic, "State"); if (supportedFeatures.contains(FEATURE_BATTERY)) { - buildOptionalChannel(newStyleChannels ? BATTERY_LEVEL_CH_ID : BATTERY_LEVEL_CH_ID_DEPRECATED, - ComponentChannelType.DIMMER, + buildOptionalChannel(BATTERY_LEVEL_CH_ID, ComponentChannelType.DIMMER, new PercentageValue(BigDecimal.ZERO, BigDecimal.valueOf(100), BigDecimal.ONE, null, null, null), - updateListener, null, null, "{{ value_json.battery_level }}", channelConfiguration.stateTopic); + updateListener, null, null, "{{ value_json.battery_level }}", channelConfiguration.stateTopic, + "Battery Level"); } } finalizeChannels(); } - // Overridden to use deprecated channel ID - @Override - protected void addJsonAttributesChannel() { - buildOptionalChannel(newStyleChannels ? JSON_ATTRIBUTES_CH_ID : JSON_ATTRIBUTES_CH_ID_DEPRECATED, - ComponentChannelType.STRING, new TextValue(), componentConfiguration.getUpdateListener(), null, null, - channelConfiguration.getJsonAttributesTemplate(), channelConfiguration.getJsonAttributesTopic()); - } - @Nullable private ComponentChannel buildOptionalChannel(String channelId, ComponentChannelType channelType, Value valueState, ChannelStateUpdateListener channelStateUpdateListener, @Nullable String commandTemplate, - @Nullable String commandTopic, @Nullable String stateTemplate, @Nullable String stateTopic) { + @Nullable String commandTopic, @Nullable String stateTemplate, @Nullable String stateTopic, String label) { if ((commandTopic != null && !commandTopic.isBlank()) || (stateTopic != null && !stateTopic.isBlank())) { - return buildChannel(channelId, channelType, valueState, getName(), channelStateUpdateListener) + return buildChannel(channelId, channelType, valueState, label, channelStateUpdateListener) .stateTopic(stateTopic, stateTemplate, channelConfiguration.getValueTemplate()) .commandTopic(commandTopic, channelConfiguration.isRetain(), channelConfiguration.getQos(), commandTemplate) diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Valve.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Valve.java index 5a0cc23cf7320..ad9c8cde5a8eb 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Valve.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Valve.java @@ -110,8 +110,8 @@ static class ChannelConfiguration extends AbstractChannelConfiguration { private final ChannelStateUpdateListener channelStateUpdateListener; private final ObjectMapper objectMapper = new ObjectMapper(); - public Valve(ComponentFactory.ComponentConfiguration componentConfiguration, boolean newStyleChannels) { - super(componentConfiguration, ChannelConfiguration.class, newStyleChannels); + public Valve(ComponentFactory.ComponentConfiguration componentConfiguration) { + super(componentConfiguration, ChannelConfiguration.class); this.channelStateUpdateListener = componentConfiguration.getUpdateListener(); AutoUpdatePolicy autoUpdatePolicy = null; diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/WaterHeater.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/WaterHeater.java index 3e79c5761aaff..b512453507813 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/WaterHeater.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/WaterHeater.java @@ -113,8 +113,8 @@ static class ChannelConfiguration extends AbstractChannelConfiguration { protected List modes = DEFAULT_MODES; } - public WaterHeater(ComponentFactory.ComponentConfiguration componentConfiguration, boolean newStyleChannels) { - super(componentConfiguration, ChannelConfiguration.class, newStyleChannels); + public WaterHeater(ComponentFactory.ComponentConfiguration componentConfiguration) { + super(componentConfiguration, ChannelConfiguration.class); if (!PLATFORM_WATER_HEATER.equals(channelConfiguration.platform)) { throw new ConfigurationException("platform must be " + PLATFORM_WATER_HEATER); diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/discovery/HomeAssistantDiscovery.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/discovery/HomeAssistantDiscovery.java index 0d8d99b29ff77..24df91e107167 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/discovery/HomeAssistantDiscovery.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/discovery/HomeAssistantDiscovery.java @@ -163,7 +163,6 @@ public void receivedMessage(ThingUID bridgeUID, MqttBrokerConnection connection, Map properties = new HashMap<>(); properties = config.appendToProperties(properties); properties.put("deviceId", thingID); - properties.put("newStyleChannels", "true"); buildResult(thingID, thingUID, config.getThingName(), haID, properties, bridgeUID); } diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/handler/HomeAssistantThingHandler.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/handler/HomeAssistantThingHandler.java index 2321641849616..193a96ced75f0 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/handler/HomeAssistantThingHandler.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/handler/HomeAssistantThingHandler.java @@ -111,7 +111,6 @@ public class HomeAssistantThingHandler extends AbstractMQTTThingHandler private Set discoveryHomeAssistantIDs = new HashSet<>(); private boolean started; - private boolean newStyleChannels; private @Nullable Update updateComponent; /** @@ -135,11 +134,8 @@ public HomeAssistantThingHandler(Thing thing, MqttChannelTypeProvider channelTyp this.unitProvider = unitProvider; this.attributeReceiveTimeout = attributeReceiveTimeout; this.delayedProcessing = new DelayedBatchProcessing<>(attributeReceiveTimeout, this, scheduler); - - newStyleChannels = "true".equals(thing.getProperties().get("newStyleChannels")); - this.discoverComponents = new DiscoverComponents(thing.getUID(), scheduler, this, this, gson, jinjava, - unitProvider, newStyleChannels); + unitProvider); } @Override @@ -187,8 +183,7 @@ public void initialize() { String channelConfigurationJSON = (String) channelConfig.get("config"); try { AbstractComponent component = ComponentFactory.createComponent(thingUID, haID, - channelConfigurationJSON, this, this, scheduler, gson, jinjava, unitProvider, - newStyleChannels); + channelConfigurationJSON, this, this, scheduler, gson, jinjava, unitProvider); if (typeID.equals(MqttBindingConstants.HOMEASSISTANT_MQTT_THING)) { typeID = calculateThingTypeUID(component); } diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/AbstractComponentTests.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/AbstractComponentTests.java index febda9cf5b8ca..97aa1bc02fa97 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/AbstractComponentTests.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/AbstractComponentTests.java @@ -82,9 +82,6 @@ public void setupThingHandler() { when(callbackMock.getBridge(eq(BRIDGE_UID))).thenReturn(bridgeThing); - if (useNewStyleChannels()) { - haThing.setProperty("newStyleChannels", "true"); - } thingHandler = new LatchThingHandler(haThing, channelTypeProvider, stateDescriptionProvider, channelTypeRegistry, unitProvider, SUBSCRIBE_TIMEOUT, ATTRIBUTE_RECEIVE_TIMEOUT); thingHandler.setConnection(bridgeConnection); @@ -109,13 +106,6 @@ public void disposeThingHandler() { */ protected abstract Set getConfigTopics(); - /** - * If new style channels should be used for this test. - */ - protected boolean useNewStyleChannels() { - return false; - } - /** * Process payload to discover and configure component. Topic should be added to {@link #getConfigTopics()} * diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/AlarmControlPanelDeprecatedTests.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/AlarmControlPanelDeprecatedTests.java deleted file mode 100644 index 6881d758b69ce..0000000000000 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/AlarmControlPanelDeprecatedTests.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Copyright (c) 2010-2024 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.mqtt.homeassistant.internal.component; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; - -import java.util.Set; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.junit.jupiter.api.Test; -import org.openhab.binding.mqtt.generic.values.TextValue; -import org.openhab.core.library.types.StringType; - -/** - * Tests for {@link AlarmControlPanel} - * - * @author Anton Kharuzhy - Initial contribution - */ -@NonNullByDefault -public class AlarmControlPanelDeprecatedTests extends AbstractComponentTests { - public static final String CONFIG_TOPIC = "alarm_control_panel/0x0000000000000000_alarm_control_panel_zigbee2mqtt"; - - @SuppressWarnings("null") - @Test - public void testAlarmControlPanel() { - // @formatter:off - var component = discoverComponent(configTopicToMqtt(CONFIG_TOPIC), - """ - { \ - "availability": [ \ - { \ - "topic": "zigbee2mqtt/bridge/state" \ - } \ - ], \ - "code": "12345", \ - "command_topic": "zigbee2mqtt/alarm/set/state", \ - "device": { \ - "identifiers": [ \ - "zigbee2mqtt_0x0000000000000000" \ - ], \ - "manufacturer": "BestAlarmEver", \ - "model": "Heavy duty super duper alarm", \ - "name": "Alarm", \ - "sw_version": "Zigbee2MQTT 1.18.2" \ - }, \ - "name": "alarm", \ - "payload_arm_away": "ARM_AWAY_", \ - "payload_arm_home": "ARM_HOME_", \ - "payload_arm_night": "ARM_NIGHT_", \ - "payload_arm_custom_bypass": "ARM_CUSTOM_BYPASS_", \ - "payload_disarm": "DISARM_", \ - "state_topic": "zigbee2mqtt/alarm/state" \ - } \ - """); - // @formatter:on - - assertThat(component.channels.size(), is(4)); - assertThat(component.getName(), is("alarm")); - - assertChannel(component, AlarmControlPanel.STATE_CHANNEL_ID_DEPRECATED, "zigbee2mqtt/alarm/state", "", "alarm", - TextValue.class); - assertChannel(component, AlarmControlPanel.SWITCH_DISARM_CHANNEL_ID, "", "zigbee2mqtt/alarm/set/state", "alarm", - TextValue.class); - assertChannel(component, AlarmControlPanel.SWITCH_ARM_AWAY_CHANNEL_ID, "", "zigbee2mqtt/alarm/set/state", - "alarm", TextValue.class); - assertChannel(component, AlarmControlPanel.SWITCH_ARM_HOME_CHANNEL_ID, "", "zigbee2mqtt/alarm/set/state", - "alarm", TextValue.class); - - publishMessage("zigbee2mqtt/alarm/state", "armed_home"); - assertState(component, AlarmControlPanel.STATE_CHANNEL_ID_DEPRECATED, new StringType("armed_home")); - publishMessage("zigbee2mqtt/alarm/state", "armed_away"); - assertState(component, AlarmControlPanel.STATE_CHANNEL_ID_DEPRECATED, new StringType("armed_away")); - - component.getChannel(AlarmControlPanel.SWITCH_DISARM_CHANNEL_ID).getState() - .publishValue(new StringType("DISARM_")); - assertPublished("zigbee2mqtt/alarm/set/state", "DISARM_"); - component.getChannel(AlarmControlPanel.SWITCH_ARM_AWAY_CHANNEL_ID).getState() - .publishValue(new StringType("ARM_AWAY_")); - assertPublished("zigbee2mqtt/alarm/set/state", "ARM_AWAY_"); - component.getChannel(AlarmControlPanel.SWITCH_ARM_HOME_CHANNEL_ID).getState() - .publishValue(new StringType("ARM_HOME_")); - assertPublished("zigbee2mqtt/alarm/set/state", "ARM_HOME_"); - } - - @Override - protected Set getConfigTopics() { - return Set.of(CONFIG_TOPIC); - } -} diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/AlarmControlPanelTests.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/AlarmControlPanelTests.java index 4ab20cac1bd7d..f5ee44a5085f5 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/AlarmControlPanelTests.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/AlarmControlPanelTests.java @@ -88,9 +88,4 @@ public void testAlarmControlPanel() { protected Set getConfigTopics() { return Set.of(CONFIG_TOPIC); } - - @Override - protected boolean useNewStyleChannels() { - return true; - } } diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/BinarySensorTests.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/BinarySensorTests.java index d11f1f82f4775..0263e34ddfa36 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/BinarySensorTests.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/BinarySensorTests.java @@ -65,7 +65,7 @@ public void test() throws InterruptedException { assertThat(component.channels.size(), is(1)); assertThat(component.getName(), is("onoffsensor")); - assertThat(component.getComponentId(), is("sn1")); + assertThat(component.getComponentId(), is("0x0000000000000000_binary_sensor_zigbee2mqtt")); assertChannel(component, BinarySensor.SENSOR_CHANNEL_ID, "zigbee2mqtt/sensor/state", "", "onoffsensor", OnOffValue.class); diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/ClimateTests.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/ClimateTests.java index 44117740821b2..6ca0b814c9026 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/ClimateTests.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/ClimateTests.java @@ -75,10 +75,9 @@ public void testTS0601Climate() { assertThat(component.getName(), is("th1")); assertChannel(component, Climate.ACTION_CH_ID, "zigbee2mqtt/th1", "", "th1", TextValue.class); - assertChannel(component, Climate.AWAY_MODE_CH_ID_DEPRECATED, "zigbee2mqtt/th1", "zigbee2mqtt/th1/set/away_mode", - "th1", OnOffValue.class); - assertChannel(component, Climate.CURRENT_TEMPERATURE_CH_ID_DEPRECATED, "zigbee2mqtt/th1", "", "th1", - NumberValue.class); + assertChannel(component, Climate.AWAY_MODE_CH_ID, "zigbee2mqtt/th1", "zigbee2mqtt/th1/set/away_mode", "th1", + OnOffValue.class); + assertChannel(component, Climate.CURRENT_TEMPERATURE_CH_ID, "zigbee2mqtt/th1", "", "th1", NumberValue.class); assertChannel(component, Climate.HOLD_CH_ID, "zigbee2mqtt/th1", "zigbee2mqtt/th1/set/preset", "th1", TextValue.class); assertChannel(component, Climate.MODE_CH_ID, "zigbee2mqtt/th1", "zigbee2mqtt/th1/set/system_mode", "th1", @@ -94,13 +93,13 @@ public void testTS0601Climate() { "current_heating_setpoint": "24"}\ """); assertState(component, Climate.ACTION_CH_ID, new StringType("off")); - assertState(component, Climate.AWAY_MODE_CH_ID_DEPRECATED, OnOffType.ON); - assertState(component, Climate.CURRENT_TEMPERATURE_CH_ID_DEPRECATED, new QuantityType<>(22.2, SIUnits.CELSIUS)); + assertState(component, Climate.AWAY_MODE_CH_ID, OnOffType.ON); + assertState(component, Climate.CURRENT_TEMPERATURE_CH_ID, new QuantityType<>(22.2, SIUnits.CELSIUS)); assertState(component, Climate.HOLD_CH_ID, new StringType("schedule")); assertState(component, Climate.MODE_CH_ID, new StringType("heat")); assertState(component, Climate.TEMPERATURE_CH_ID, new QuantityType<>(24, SIUnits.CELSIUS)); - component.getChannel(Climate.AWAY_MODE_CH_ID_DEPRECATED).getState().publishValue(OnOffType.OFF); + component.getChannel(Climate.AWAY_MODE_CH_ID).getState().publishValue(OnOffType.OFF); assertPublished("zigbee2mqtt/th1/set/away_mode", "OFF"); component.getChannel(Climate.HOLD_CH_ID).getState().publishValue(new StringType("eco")); assertPublished("zigbee2mqtt/th1/set/preset", "eco"); @@ -147,10 +146,9 @@ public void testTS0601ClimateNotSendIfOff() { assertThat(component.getName(), is("th1")); assertChannel(component, Climate.ACTION_CH_ID, "zigbee2mqtt/th1", "", "th1", TextValue.class); - assertChannel(component, Climate.AWAY_MODE_CH_ID_DEPRECATED, "zigbee2mqtt/th1", "zigbee2mqtt/th1/set/away_mode", - "th1", OnOffValue.class); - assertChannel(component, Climate.CURRENT_TEMPERATURE_CH_ID_DEPRECATED, "zigbee2mqtt/th1", "", "th1", - NumberValue.class); + assertChannel(component, Climate.AWAY_MODE_CH_ID, "zigbee2mqtt/th1", "zigbee2mqtt/th1/set/away_mode", "th1", + OnOffValue.class); + assertChannel(component, Climate.CURRENT_TEMPERATURE_CH_ID, "zigbee2mqtt/th1", "", "th1", NumberValue.class); assertChannel(component, Climate.HOLD_CH_ID, "zigbee2mqtt/th1", "zigbee2mqtt/th1/set/preset", "th1", TextValue.class); assertChannel(component, Climate.MODE_CH_ID, "zigbee2mqtt/th1", "zigbee2mqtt/th1/set/system_mode", "th1", @@ -166,14 +164,14 @@ public void testTS0601ClimateNotSendIfOff() { "current_heating_setpoint": "24"}\ """); assertState(component, Climate.ACTION_CH_ID, new StringType("off")); - assertState(component, Climate.AWAY_MODE_CH_ID_DEPRECATED, OnOffType.ON); - assertState(component, Climate.CURRENT_TEMPERATURE_CH_ID_DEPRECATED, new QuantityType<>(22.2, SIUnits.CELSIUS)); + assertState(component, Climate.AWAY_MODE_CH_ID, OnOffType.ON); + assertState(component, Climate.CURRENT_TEMPERATURE_CH_ID, new QuantityType<>(22.2, SIUnits.CELSIUS)); assertState(component, Climate.HOLD_CH_ID, new StringType("schedule")); assertState(component, Climate.MODE_CH_ID, new StringType("heat")); assertState(component, Climate.TEMPERATURE_CH_ID, new QuantityType<>(24, SIUnits.CELSIUS)); // Climate is in OFF state - component.getChannel(Climate.AWAY_MODE_CH_ID_DEPRECATED).getState().publishValue(OnOffType.OFF); + component.getChannel(Climate.AWAY_MODE_CH_ID).getState().publishValue(OnOffType.OFF); assertNotPublished("zigbee2mqtt/th1/set/away_mode", "OFF"); component.getChannel(Climate.HOLD_CH_ID).getState().publishValue(new StringType("eco")); assertNotPublished("zigbee2mqtt/th1/set/preset", "eco"); @@ -192,7 +190,7 @@ public void testTS0601ClimateNotSendIfOff() { """); // Climate is in ON state - component.getChannel(Climate.AWAY_MODE_CH_ID_DEPRECATED).getState().publishValue(OnOffType.OFF); + component.getChannel(Climate.AWAY_MODE_CH_ID).getState().publishValue(OnOffType.OFF); assertPublished("zigbee2mqtt/th1/set/away_mode", "OFF"); component.getChannel(Climate.HOLD_CH_ID).getState().publishValue(new StringType("eco")); assertPublished("zigbee2mqtt/th1/set/preset", "eco"); @@ -255,12 +253,12 @@ public void testClimate() { assertChannel(component, Climate.ACTION_CH_ID, "zigbee2mqtt/th1", "", "MQTT HVAC", TextValue.class); assertChannel(component, Climate.AUX_CH_ID, "zigbee2mqtt/th1", "zigbee2mqtt/th1/aux", "MQTT HVAC", OnOffValue.class); - assertChannel(component, Climate.AWAY_MODE_CH_ID_DEPRECATED, "zigbee2mqtt/th1", "zigbee2mqtt/th1/away_mode", - "MQTT HVAC", OnOffValue.class); - assertChannel(component, Climate.CURRENT_TEMPERATURE_CH_ID_DEPRECATED, "zigbee2mqtt/th1", "", "MQTT HVAC", + assertChannel(component, Climate.AWAY_MODE_CH_ID, "zigbee2mqtt/th1", "zigbee2mqtt/th1/away_mode", "MQTT HVAC", + OnOffValue.class); + assertChannel(component, Climate.CURRENT_TEMPERATURE_CH_ID, "zigbee2mqtt/th1", "", "MQTT HVAC", NumberValue.class); - assertChannel(component, Climate.FAN_MODE_CH_ID_DEPRECATED, "zigbee2mqtt/th1", "zigbee2mqtt/th1/fan_mode", - "MQTT HVAC", TextValue.class); + assertChannel(component, Climate.FAN_MODE_CH_ID, "zigbee2mqtt/th1", "zigbee2mqtt/th1/fan_mode", "MQTT HVAC", + TextValue.class); assertChannel(component, Climate.HOLD_CH_ID, "zigbee2mqtt/th1", "zigbee2mqtt/th1/hold", "MQTT HVAC", TextValue.class); assertChannel(component, Climate.MODE_CH_ID, "zigbee2mqtt/th1", "zigbee2mqtt/th1/mode", "MQTT HVAC", @@ -269,10 +267,10 @@ public void testClimate() { TextValue.class); assertChannel(component, Climate.TEMPERATURE_CH_ID, "zigbee2mqtt/th1", "zigbee2mqtt/th1/temperature", "MQTT HVAC", NumberValue.class); - assertChannel(component, Climate.TEMPERATURE_HIGH_CH_ID_DEPRECATED, "zigbee2mqtt/th1", - "zigbee2mqtt/th1/temperature_high", "MQTT HVAC", NumberValue.class); - assertChannel(component, Climate.TEMPERATURE_LOW_CH_ID_DEPRECATED, "zigbee2mqtt/th1", - "zigbee2mqtt/th1/temperature_low", "MQTT HVAC", NumberValue.class); + assertChannel(component, Climate.TEMPERATURE_HIGH_CH_ID, "zigbee2mqtt/th1", "zigbee2mqtt/th1/temperature_high", + "MQTT HVAC", NumberValue.class); + assertChannel(component, Climate.TEMPERATURE_LOW_CH_ID, "zigbee2mqtt/th1", "zigbee2mqtt/th1/temperature_low", + "MQTT HVAC", NumberValue.class); assertChannel(component, Climate.POWER_CH_ID, "", "zigbee2mqtt/th1/power", "MQTT HVAC", OnOffValue.class); assertChannel(component, Climate.JSON_ATTRIBUTES_CHANNEL_ID, "zigbee2mqtt/th1", "", "JSON Attributes", TextValue.class); @@ -286,24 +284,21 @@ public void testClimate() { assertState(component, Climate.ACTION_CH_ID, new StringType("fan")); assertState(component, Climate.AUX_CH_ID, OnOffType.ON); - assertState(component, Climate.AWAY_MODE_CH_ID_DEPRECATED, OnOffType.OFF); - assertState(component, Climate.CURRENT_TEMPERATURE_CH_ID_DEPRECATED, - new QuantityType<>(35.5, ImperialUnits.FAHRENHEIT)); - assertState(component, Climate.FAN_MODE_CH_ID_DEPRECATED, new StringType("p2")); + assertState(component, Climate.AWAY_MODE_CH_ID, OnOffType.OFF); + assertState(component, Climate.CURRENT_TEMPERATURE_CH_ID, new QuantityType<>(35.5, ImperialUnits.FAHRENHEIT)); + assertState(component, Climate.FAN_MODE_CH_ID, new StringType("p2")); assertState(component, Climate.HOLD_CH_ID, new StringType("u2")); assertState(component, Climate.MODE_CH_ID, new StringType("B1")); assertState(component, Climate.SWING_CH_ID, new StringType("G1")); assertState(component, Climate.TEMPERATURE_CH_ID, new QuantityType<>(30, ImperialUnits.FAHRENHEIT)); - assertState(component, Climate.TEMPERATURE_HIGH_CH_ID_DEPRECATED, - new QuantityType<>(37, ImperialUnits.FAHRENHEIT)); - assertState(component, Climate.TEMPERATURE_LOW_CH_ID_DEPRECATED, - new QuantityType<>(20, ImperialUnits.FAHRENHEIT)); + assertState(component, Climate.TEMPERATURE_HIGH_CH_ID, new QuantityType<>(37, ImperialUnits.FAHRENHEIT)); + assertState(component, Climate.TEMPERATURE_LOW_CH_ID, new QuantityType<>(20, ImperialUnits.FAHRENHEIT)); component.getChannel(Climate.AUX_CH_ID).getState().publishValue(OnOffType.OFF); assertPublished("zigbee2mqtt/th1/aux", "OFF"); - component.getChannel(Climate.AWAY_MODE_CH_ID_DEPRECATED).getState().publishValue(OnOffType.ON); + component.getChannel(Climate.AWAY_MODE_CH_ID).getState().publishValue(OnOffType.ON); assertPublished("zigbee2mqtt/th1/away_mode", "ON"); - component.getChannel(Climate.FAN_MODE_CH_ID_DEPRECATED).getState().publishValue(new StringType("p1")); + component.getChannel(Climate.FAN_MODE_CH_ID).getState().publishValue(new StringType("p1")); assertPublished("zigbee2mqtt/th1/fan_mode", "fan_mode=p1"); component.getChannel(Climate.HOLD_CH_ID).getState().publishValue(new StringType("u3")); assertPublished("zigbee2mqtt/th1/hold", "hold=u3"); @@ -313,9 +308,9 @@ public void testClimate() { assertPublished("zigbee2mqtt/th1/swing", "swing=G2"); component.getChannel(Climate.TEMPERATURE_CH_ID).getState().publishValue(new DecimalType(30.5)); assertPublished("zigbee2mqtt/th1/temperature", "temperature=30.5"); - component.getChannel(Climate.TEMPERATURE_HIGH_CH_ID_DEPRECATED).getState().publishValue(new DecimalType(39.5)); + component.getChannel(Climate.TEMPERATURE_HIGH_CH_ID).getState().publishValue(new DecimalType(39.5)); assertPublished("zigbee2mqtt/th1/temperature_high", "temperature_high=39.5"); - component.getChannel(Climate.TEMPERATURE_LOW_CH_ID_DEPRECATED).getState().publishValue(new DecimalType(19.5)); + component.getChannel(Climate.TEMPERATURE_LOW_CH_ID).getState().publishValue(new DecimalType(19.5)); assertPublished("zigbee2mqtt/th1/temperature_low", "temperature_low=19.5"); component.getChannel(Climate.POWER_CH_ID).getState().publishValue(OnOffType.OFF); assertPublished("zigbee2mqtt/th1/power", "OFF"); diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/DefaultSchemaLightTests.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/DefaultSchemaLightTests.java index 802c6b4de964e..3d70428e348d6 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/DefaultSchemaLightTests.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/DefaultSchemaLightTests.java @@ -274,16 +274,16 @@ public void testOnOffOnly() throws InterruptedException { assertThat(component.channels.size(), is(1)); assertThat(component.getName(), is("light")); - assertChannel(component, Light.SWITCH_CHANNEL_ID_DEPRECATED, "zigbee2mqtt/light/state", - "zigbee2mqtt/light/set/state", "On/Off State", OnOffValue.class); + assertChannel(component, Light.SWITCH_CHANNEL_ID, "zigbee2mqtt/light/state", "zigbee2mqtt/light/set/state", + "On/Off State", OnOffValue.class); assertThat(component.brightnessChannel, is(nullValue())); publishMessage("zigbee2mqtt/light/state", "{\"power\": \"ON_\"}"); - assertState(component, Light.SWITCH_CHANNEL_ID_DEPRECATED, OnOffType.ON); + assertState(component, Light.SWITCH_CHANNEL_ID, OnOffType.ON); publishMessage("zigbee2mqtt/light/state", "{\"power\": \"OFF_\"}"); - assertState(component, Light.SWITCH_CHANNEL_ID_DEPRECATED, OnOffType.OFF); + assertState(component, Light.SWITCH_CHANNEL_ID, OnOffType.OFF); - sendCommand(component, Light.SWITCH_CHANNEL_ID_DEPRECATED, OnOffType.OFF); + sendCommand(component, Light.SWITCH_CHANNEL_ID, OnOffType.OFF); assertPublished("zigbee2mqtt/light/set/state", "OFF_"); } @@ -305,17 +305,17 @@ public void testOnOffWithEffect() throws InterruptedException { assertThat(component.channels.size(), is(2)); assertThat(component.getName(), is("light")); - assertChannel(component, Light.SWITCH_CHANNEL_ID_DEPRECATED, "zigbee2mqtt/light/state", - "zigbee2mqtt/light/set/state", "On/Off State", OnOffValue.class); + assertChannel(component, Light.SWITCH_CHANNEL_ID, "zigbee2mqtt/light/state", "zigbee2mqtt/light/set/state", + "On/Off State", OnOffValue.class); assertChannel(component, Light.EFFECT_CHANNEL_ID, "zigbee2mqtt/light/effect", "zigbee2mqtt/light/set/effect", "Lighting Effect", TextValue.class); publishMessage("zigbee2mqtt/light/state", "{\"power\": \"ON\"}"); - assertState(component, Light.SWITCH_CHANNEL_ID_DEPRECATED, OnOffType.ON); + assertState(component, Light.SWITCH_CHANNEL_ID, OnOffType.ON); publishMessage("zigbee2mqtt/light/effect", "party"); assertState(component, Light.EFFECT_CHANNEL_ID, new StringType("party")); publishMessage("zigbee2mqtt/light/state", "{\"power\": \"OFF\"}"); - assertState(component, Light.SWITCH_CHANNEL_ID_DEPRECATED, OnOffType.OFF); + assertState(component, Light.SWITCH_CHANNEL_ID, OnOffType.OFF); sendCommand(component, Light.EFFECT_CHANNEL_ID, new StringType("rainbow")); assertPublished("zigbee2mqtt/light/set/effect", "rainbow"); diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/DeviceTriggerTests.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/DeviceTriggerTests.java index a45c1eac3479d..6ed0b7acbd638 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/DeviceTriggerTests.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/DeviceTriggerTests.java @@ -145,9 +145,4 @@ public void testMerge() throws InterruptedException { protected Set getConfigTopics() { return Set.of(CONFIG_TOPIC_1, CONFIG_TOPIC_2); } - - @Override - protected boolean useNewStyleChannels() { - return true; - } } diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/FanTests.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/FanTests.java index 7978ff0d13717..bc78602428ea2 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/FanTests.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/FanTests.java @@ -73,21 +73,21 @@ public void test() throws InterruptedException { assertThat(component.channels.size(), is(1)); assertThat(component.getName(), is("fan")); - assertChannel(component, Fan.SWITCH_CHANNEL_ID_DEPRECATED, "zigbee2mqtt/fan/state", "zigbee2mqtt/fan/set/state", + assertChannel(component, Fan.SWITCH_CHANNEL_ID, "zigbee2mqtt/fan/state", "zigbee2mqtt/fan/set/state", "On/Off State", OnOffValue.class, null); publishMessage("zigbee2mqtt/fan/state", "ON_"); - assertState(component, Fan.SWITCH_CHANNEL_ID_DEPRECATED, OnOffType.ON); + assertState(component, Fan.SWITCH_CHANNEL_ID, OnOffType.ON); publishMessage("zigbee2mqtt/fan/state", "ON_"); - assertState(component, Fan.SWITCH_CHANNEL_ID_DEPRECATED, OnOffType.ON); + assertState(component, Fan.SWITCH_CHANNEL_ID, OnOffType.ON); publishMessage("zigbee2mqtt/fan/state", "OFF_"); - assertState(component, Fan.SWITCH_CHANNEL_ID_DEPRECATED, OnOffType.OFF); + assertState(component, Fan.SWITCH_CHANNEL_ID, OnOffType.OFF); publishMessage("zigbee2mqtt/fan/state", "ON_"); - assertState(component, Fan.SWITCH_CHANNEL_ID_DEPRECATED, OnOffType.ON); + assertState(component, Fan.SWITCH_CHANNEL_ID, OnOffType.ON); - component.getChannel(Fan.SWITCH_CHANNEL_ID_DEPRECATED).getState().publishValue(OnOffType.OFF); + component.getChannel(Fan.SWITCH_CHANNEL_ID).getState().publishValue(OnOffType.OFF); assertPublished("zigbee2mqtt/fan/set/state", "OFF_"); - component.getChannel(Fan.SWITCH_CHANNEL_ID_DEPRECATED).getState().publishValue(OnOffType.ON); + component.getChannel(Fan.SWITCH_CHANNEL_ID).getState().publishValue(OnOffType.ON); assertPublished("zigbee2mqtt/fan/set/state", "ON_"); } @@ -187,7 +187,7 @@ public void testInferredOptimistic() throws InterruptedException { assertThat(component.channels.size(), is(1)); assertThat(component.getName(), is("fan")); - assertChannel(component, Fan.SWITCH_CHANNEL_ID_DEPRECATED, "", "zigbee2mqtt/fan/set/state", "On/Off State", + assertChannel(component, Fan.SWITCH_CHANNEL_ID, "", "zigbee2mqtt/fan/set/state", "On/Off State", OnOffValue.class, AutoUpdatePolicy.RECOMMEND); } @@ -225,7 +225,7 @@ public void testForcedOptimistic() throws InterruptedException { assertThat(component.channels.size(), is(1)); assertThat(component.getName(), is("fan")); - assertChannel(component, Fan.SWITCH_CHANNEL_ID_DEPRECATED, "zigbee2mqtt/fan/state", "zigbee2mqtt/fan/set/state", + assertChannel(component, Fan.SWITCH_CHANNEL_ID, "zigbee2mqtt/fan/state", "zigbee2mqtt/fan/set/state", "On/Off State", OnOffValue.class, AutoUpdatePolicy.RECOMMEND); } @@ -296,7 +296,7 @@ public void testCommandTemplate() throws InterruptedException { assertThat(component.channels.size(), is(1)); - component.getChannel(Fan.SWITCH_CHANNEL_ID_DEPRECATED).getState().publishValue(OnOffType.OFF); + component.getChannel(Fan.SWITCH_CHANNEL_ID).getState().publishValue(OnOffType.OFF); assertPublished("zigbee2mqtt/fan/set/state", "set to OFF_"); } diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/JSONSchemaLightTests.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/JSONSchemaLightTests.java index 083d9151d3fa1..75e3c4de3f37b 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/JSONSchemaLightTests.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/JSONSchemaLightTests.java @@ -203,16 +203,16 @@ public void testOnOffOnly() throws InterruptedException { assertThat(component.channels.size(), is(1)); assertThat(component.getName(), is("light")); - assertChannel(component, Light.SWITCH_CHANNEL_ID_DEPRECATED, "", "dummy", "On/Off State", OnOffValue.class); + assertChannel(component, Light.SWITCH_CHANNEL_ID, "", "dummy", "On/Off State", OnOffValue.class); publishMessage("zigbee2mqtt/light/state", "{ \"state\": \"ON\" }"); - assertState(component, Light.SWITCH_CHANNEL_ID_DEPRECATED, OnOffType.ON); + assertState(component, Light.SWITCH_CHANNEL_ID, OnOffType.ON); publishMessage("zigbee2mqtt/light/state", "{ \"state\": \"OFF\" }"); - assertState(component, Light.SWITCH_CHANNEL_ID_DEPRECATED, OnOffType.OFF); + assertState(component, Light.SWITCH_CHANNEL_ID, OnOffType.OFF); - sendCommand(component, Light.SWITCH_CHANNEL_ID_DEPRECATED, OnOffType.OFF); + sendCommand(component, Light.SWITCH_CHANNEL_ID, OnOffType.OFF); assertPublished("zigbee2mqtt/light/set/state", "{\"state\":\"OFF\"}"); - sendCommand(component, Light.SWITCH_CHANNEL_ID_DEPRECATED, OnOffType.ON); + sendCommand(component, Light.SWITCH_CHANNEL_ID, OnOffType.ON); assertPublished("zigbee2mqtt/light/set/state", "{\"state\":\"ON\"}"); } diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/SensorTests.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/SensorTests.java index d712ee20317b3..e046c8d23d89a 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/SensorTests.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/SensorTests.java @@ -65,7 +65,7 @@ public void test() throws InterruptedException { assertThat(component.channels.size(), is(1)); assertThat(component.getName(), is("sensor1")); - assertThat(component.getComponentId(), is("sn1")); + assertThat(component.getComponentId(), is("0x0000000000000000_sensor_zigbee2mqtt")); assertChannel(component, Sensor.SENSOR_CHANNEL_ID, "zigbee2mqtt/sensor/state", "", "sensor1", NumberValue.class); diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/TemplateSchemaLightTests.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/TemplateSchemaLightTests.java index c7be8675705d0..856b35f79ee6d 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/TemplateSchemaLightTests.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/TemplateSchemaLightTests.java @@ -151,12 +151,11 @@ public void testBrightnessAndCCT() throws InterruptedException { assertThat(component.getName(), is("Bulb-white")); assertChannel(component, Light.BRIGHTNESS_CHANNEL_ID, "", "dummy", "Brightness", PercentageValue.class); - assertChannel(component, Light.COLOR_TEMP_CHANNEL_ID_DEPRECATED, "", "dummy", "Color Temperature", - NumberValue.class); + assertChannel(component, Light.COLOR_TEMP_CHANNEL_ID, "", "dummy", "Color Temperature", NumberValue.class); publishMessage("shellies/bulb/color/0/status", "{ \"state\": \"on\", \"brightness\": 100 }"); assertState(component, Light.BRIGHTNESS_CHANNEL_ID, PercentType.HUNDRED); - assertState(component, Light.COLOR_TEMP_CHANNEL_ID_DEPRECATED, UnDefType.NULL); + assertState(component, Light.COLOR_TEMP_CHANNEL_ID, UnDefType.NULL); sendCommand(component, Light.BRIGHTNESS_CHANNEL_ID, PercentType.HUNDRED); assertPublished("shellies/bulb/color/0/set", "{\"turn\": \"on\", \"mode\": \"white\", \"brightness\": 100}"); @@ -164,7 +163,7 @@ public void testBrightnessAndCCT() throws InterruptedException { sendCommand(component, Light.BRIGHTNESS_CHANNEL_ID, OnOffType.OFF); assertPublished("shellies/bulb/color/0/set", "{\"turn\":\"off\", \"mode\": \"white\"}"); - sendCommand(component, Light.COLOR_TEMP_CHANNEL_ID_DEPRECATED, new QuantityType(200, Units.MIRED)); + sendCommand(component, Light.COLOR_TEMP_CHANNEL_ID, new QuantityType(200, Units.MIRED)); assertPublished("shellies/bulb/color/0/set", "{\"turn\": \"on\", \"mode\": \"white\", \"temp\": 5000}"); } @@ -185,16 +184,16 @@ public void testOnOffOnly() throws InterruptedException { assertThat(component.channels.size(), is(1)); assertThat(component.getName(), is("light")); - assertChannel(component, Light.SWITCH_CHANNEL_ID_DEPRECATED, "", "dummy", "On/Off State", OnOffValue.class); + assertChannel(component, Light.SWITCH_CHANNEL_ID, "", "dummy", "On/Off State", OnOffValue.class); publishMessage("zigbee2mqtt/light/state", "{\"power\": \"on\"}"); - assertState(component, Light.SWITCH_CHANNEL_ID_DEPRECATED, OnOffType.ON); + assertState(component, Light.SWITCH_CHANNEL_ID, OnOffType.ON); publishMessage("zigbee2mqtt/light/state", "{\"power\": \"off\"}"); - assertState(component, Light.SWITCH_CHANNEL_ID_DEPRECATED, OnOffType.OFF); + assertState(component, Light.SWITCH_CHANNEL_ID, OnOffType.OFF); - sendCommand(component, Light.SWITCH_CHANNEL_ID_DEPRECATED, OnOffType.OFF); + sendCommand(component, Light.SWITCH_CHANNEL_ID, OnOffType.OFF); assertPublished("zigbee2mqtt/light/set/state", "off"); - sendCommand(component, Light.SWITCH_CHANNEL_ID_DEPRECATED, OnOffType.ON); + sendCommand(component, Light.SWITCH_CHANNEL_ID, OnOffType.ON); assertPublished("zigbee2mqtt/light/set/state", "on"); } diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/VacuumTests.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/VacuumTests.java index 60490f930f613..290e8addd381b 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/VacuumTests.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/VacuumTests.java @@ -64,21 +64,21 @@ public void testRoborockValetudo() { assertThat(component.channels.size(), is(6)); // command, state, fan speed, send command, battery, json attrs assertThat(component.getName(), is("Rockrobo")); - assertChannel(component, Vacuum.COMMAND_CH_ID, "", "valetudo/rockrobo/command", "Rockrobo", TextValue.class); - assertChannel(component, Vacuum.STATE_CH_ID, "valetudo/rockrobo/state", "", "Rockrobo", TextValue.class); - assertChannel(component, Vacuum.FAN_SPEED_CH_ID_DEPRECATED, "valetudo/rockrobo/state", - "valetudo/rockrobo/set_fan_speed", "Rockrobo", TextValue.class); - assertChannel(component, Vacuum.CUSTOM_COMMAND_CH_ID_DEPRECATED, "", "valetudo/rockrobo/custom_command", - "Rockrobo", TextValue.class); - assertChannel(component, Vacuum.BATTERY_LEVEL_CH_ID_DEPRECATED, "valetudo/rockrobo/state", "", "Rockrobo", + assertChannel(component, Vacuum.COMMAND_CH_ID, "", "valetudo/rockrobo/command", "Command", TextValue.class); + assertChannel(component, Vacuum.STATE_CH_ID, "valetudo/rockrobo/state", "", "State", TextValue.class); + assertChannel(component, Vacuum.FAN_SPEED_CH_ID, "valetudo/rockrobo/state", "valetudo/rockrobo/set_fan_speed", + "Fan Speed", TextValue.class); + assertChannel(component, Vacuum.CUSTOM_COMMAND_CH_ID, "", "valetudo/rockrobo/custom_command", "Custom Command", + TextValue.class); + assertChannel(component, Vacuum.BATTERY_LEVEL_CH_ID, "valetudo/rockrobo/state", "", "Battery Level", PercentageValue.class); - assertChannel(component, Vacuum.JSON_ATTRIBUTES_CH_ID_DEPRECATED, "valetudo/rockrobo/attributes", "", - "Rockrobo", TextValue.class); + assertChannel(component, Vacuum.JSON_ATTRIBUTES_CH_ID, "valetudo/rockrobo/attributes", "", "JSON Attributes", + TextValue.class); assertState(component, Vacuum.STATE_CH_ID, UnDefType.UNDEF); - assertState(component, Vacuum.FAN_SPEED_CH_ID_DEPRECATED, UnDefType.UNDEF); - assertState(component, Vacuum.BATTERY_LEVEL_CH_ID_DEPRECATED, UnDefType.UNDEF); - assertState(component, Vacuum.JSON_ATTRIBUTES_CH_ID_DEPRECATED, UnDefType.UNDEF); + assertState(component, Vacuum.FAN_SPEED_CH_ID, UnDefType.UNDEF); + assertState(component, Vacuum.BATTERY_LEVEL_CH_ID, UnDefType.UNDEF); + assertState(component, Vacuum.JSON_ATTRIBUTES_CH_ID, UnDefType.UNDEF); // @formatter:off String jsonValue; @@ -124,9 +124,9 @@ public void testRoborockValetudo() { // @formatter:on assertState(component, Vacuum.STATE_CH_ID, new StringType(Vacuum.STATE_DOCKED)); - assertState(component, Vacuum.FAN_SPEED_CH_ID_DEPRECATED, new StringType("max")); - assertState(component, Vacuum.BATTERY_LEVEL_CH_ID_DEPRECATED, new PercentType(100)); - assertState(component, Vacuum.JSON_ATTRIBUTES_CH_ID_DEPRECATED, new StringType(jsonValue)); + assertState(component, Vacuum.FAN_SPEED_CH_ID, new StringType("max")); + assertState(component, Vacuum.BATTERY_LEVEL_CH_ID, new PercentType(100)); + assertState(component, Vacuum.JSON_ATTRIBUTES_CH_ID, new StringType(jsonValue)); component.getChannel(Vacuum.COMMAND_CH_ID).getState().publishValue(new StringType("start")); assertPublished("valetudo/rockrobo/command", "start"); @@ -142,11 +142,11 @@ public void testRoborockValetudo() { // @formatter:on assertState(component, Vacuum.STATE_CH_ID, new StringType(Vacuum.STATE_CLEANING)); - assertState(component, Vacuum.FAN_SPEED_CH_ID_DEPRECATED, new StringType("max")); - assertState(component, Vacuum.BATTERY_LEVEL_CH_ID_DEPRECATED, new PercentType(99)); - assertState(component, Vacuum.JSON_ATTRIBUTES_CH_ID_DEPRECATED, new StringType(jsonValue)); + assertState(component, Vacuum.FAN_SPEED_CH_ID, new StringType("max")); + assertState(component, Vacuum.BATTERY_LEVEL_CH_ID, new PercentType(99)); + assertState(component, Vacuum.JSON_ATTRIBUTES_CH_ID, new StringType(jsonValue)); - component.getChannel(Vacuum.FAN_SPEED_CH_ID_DEPRECATED).getState().publishValue(new StringType("medium")); + component.getChannel(Vacuum.FAN_SPEED_CH_ID).getState().publishValue(new StringType("medium")); assertPublished("valetudo/rockrobo/set_fan_speed", "medium"); // @formatter:off @@ -160,9 +160,9 @@ public void testRoborockValetudo() { // @formatter:on assertState(component, Vacuum.STATE_CH_ID, new StringType(Vacuum.STATE_RETURNING)); - assertState(component, Vacuum.FAN_SPEED_CH_ID_DEPRECATED, new StringType("medium")); - assertState(component, Vacuum.BATTERY_LEVEL_CH_ID_DEPRECATED, new PercentType(80)); - assertState(component, Vacuum.JSON_ATTRIBUTES_CH_ID_DEPRECATED, new StringType(jsonValue)); + assertState(component, Vacuum.FAN_SPEED_CH_ID, new StringType("medium")); + assertState(component, Vacuum.BATTERY_LEVEL_CH_ID, new PercentType(80)); + assertState(component, Vacuum.JSON_ATTRIBUTES_CH_ID, new StringType(jsonValue)); } @Override diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/handler/HomeAssistantThingHandlerTests.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/handler/HomeAssistantThingHandlerTests.java index 964bc63879685..25b583be15f95 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/handler/HomeAssistantThingHandlerTests.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/handler/HomeAssistantThingHandlerTests.java @@ -222,13 +222,13 @@ public void testDuplicateComponentPublish() throws InterruptedException { // // verify that both channels are there and the label corresponds to newer discovery topic payload // - Channel corridorTempChannel = nonSpyThingHandler.getThing().getChannel("tempCorridor_5Fsensor#sensor"); + Channel corridorTempChannel = nonSpyThingHandler.getThing().getChannel("tempCorridor"); assertThat("Corridor temperature channel is created", corridorTempChannel, notNullValue()); Objects.requireNonNull(corridorTempChannel); // for compiler assertThat("Corridor temperature channel is having the updated label from 2nd discovery topic publish", corridorTempChannel.getLabel(), is("CorridorTemp NEW")); - Channel outsideTempChannel = nonSpyThingHandler.getThing().getChannel("tempOutside_5Fsensor#sensor"); + Channel outsideTempChannel = nonSpyThingHandler.getThing().getChannel("tempOutside"); assertThat("Outside temperature channel is created", outsideTempChannel, notNullValue()); verify(thingHandler, times(2)).componentDiscovered(eq(new HaID(configTopicTempCorridor)), any(Sensor.class)); @@ -347,7 +347,6 @@ public void testRestoreComponentFromChannelConfig() { haThing = ThingBuilder.create(HA_TYPE_UID, HA_UID).withBridge(BRIDGE_UID).withChannel(channelBuilder.build()) .withConfiguration(thingConfiguration).build(); - haThing.setProperty("newStyleChannels", "true"); setupThingHandler(); thingHandler.initialize(); @@ -358,58 +357,6 @@ public void testRestoreComponentFromChannelConfig() { @Test public void testDuplicateChannelId() { - thingHandler.initialize(); - - verify(callbackMock).statusUpdated(eq(haThing), any()); - // Expect a call to the bridge status changed, the start, the propertiesChanged method - verify(thingHandler).bridgeStatusChanged(any()); - verify(thingHandler, timeout(SUBSCRIBE_TIMEOUT)).start(any()); - - MQTT_TOPICS.forEach(t -> { - verify(bridgeConnection, timeout(SUBSCRIBE_TIMEOUT)).subscribe(eq(t), any()); - }); - - verify(thingHandler, never()).componentDiscovered(any(), any()); - assertThat(haThing.getChannels().size(), is(0)); - - thingHandler.discoverComponents.processMessage("homeassistant/number/abc/activeEnergyReports/config", """ - { - "name":"ActiveEnergyReports", - "object_id":"mud_room_cans_switch_(garage)_activeEnergyReports", - "state_topic":"zigbee2mqtt/Mud Room Cans Switch (Garage)", - "unique_id":"0x04cd15fffedb7f81_activeEnergyReports_zigbee2mqtt", - "value_template":"{{ value_json.activeEnergyReports }}" - } - """.getBytes(StandardCharsets.UTF_8)); - thingHandler.discoverComponents.processMessage("homeassistant/sensor/abc/activeEnergyReports/config", """ - { - "command_topic":"zigbee2mqtt/Mud Room Cans Switch (Garage)/set/activeEnergyReports", - "max":32767, - "min":0, - "name":"ActiveEnergyReports", - "object_id":"mud_room_cans_switch_(garage)_activeEnergyReports", - "state_topic":"zigbee2mqtt/Mud Room Cans Switch (Garage)", - "unique_id":"0x04cd15fffedb7f81_activeEnergyReports_zigbee2mqtt", - "value_template":"{{ value_json.activeEnergyReports }}" - } - """.getBytes(StandardCharsets.UTF_8)); - thingHandler.delayedProcessing.forceProcessNow(); - waitForAssert(() -> { - assertThat("2 channels created", nonSpyThingHandler.getThing().getChannels().size() == 2); - }); - - Channel numberChannel = nonSpyThingHandler.getThing() - .getChannel("0x04cd15fffedb7f81_5FactiveEnergyReports_5Fzigbee2mqtt_number#number"); - assertThat("Number channel is created", numberChannel, notNullValue()); - - Channel sensorChannel = nonSpyThingHandler.getThing() - .getChannel("0x04cd15fffedb7f81_5FactiveEnergyReports_5Fzigbee2mqtt_sensor#sensor"); - assertThat("Sensor channel is created", sensorChannel, notNullValue()); - } - - @Test - public void testDuplicateChannelIdNewStyleChannels() { - haThing.setProperty("newStyleChannels", "true"); thingHandler = new HomeAssistantThingHandler(haThing, channelTypeProvider, stateDescriptionProvider, channelTypeRegistry, new Jinjava(), unitProvider, SUBSCRIBE_TIMEOUT, ATTRIBUTE_RECEIVE_TIMEOUT); thingHandler.setConnection(bridgeConnection); @@ -465,8 +412,7 @@ public void testDuplicateChannelIdNewStyleChannels() { } @Test - public void testDuplicateChannelIdNewStyleChannelsComplex() { - haThing.setProperty("newStyleChannels", "true"); + public void testDuplicateChannelIdComplex() { thingHandler = new HomeAssistantThingHandler(haThing, channelTypeProvider, stateDescriptionProvider, channelTypeRegistry, new Jinjava(), unitProvider, SUBSCRIBE_TIMEOUT, ATTRIBUTE_RECEIVE_TIMEOUT); thingHandler.setConnection(bridgeConnection); diff --git a/itests/org.openhab.binding.mqtt.homeassistant.tests/src/main/java/org/openhab/binding/mqtt/homeassistant/DiscoverComponentsTest.java b/itests/org.openhab.binding.mqtt.homeassistant.tests/src/main/java/org/openhab/binding/mqtt/homeassistant/DiscoverComponentsTest.java index be1d2c73cb30c..ac3f28d7fa24c 100644 --- a/itests/org.openhab.binding.mqtt.homeassistant.tests/src/main/java/org/openhab/binding/mqtt/homeassistant/DiscoverComponentsTest.java +++ b/itests/org.openhab.binding.mqtt.homeassistant.tests/src/main/java/org/openhab/binding/mqtt/homeassistant/DiscoverComponentsTest.java @@ -85,7 +85,7 @@ public void discoveryTimeTest() throws InterruptedException, ExecutionException, UnitProvider unitProvider = mock(UnitProvider.class); DiscoverComponents discover = spy(new DiscoverComponents(ThingChannelConstants.TEST_HOME_ASSISTANT_THING, - scheduler, channelStateUpdateListener, availabilityTracker, gson, jinjava, unitProvider, true)); + scheduler, channelStateUpdateListener, availabilityTracker, gson, jinjava, unitProvider)); HandlerConfiguration config = new HandlerConfiguration("homeassistant", List.of("switch/object")); diff --git a/itests/org.openhab.binding.mqtt.homeassistant.tests/src/main/java/org/openhab/binding/mqtt/homeassistant/HomeAssistantMQTTImplementationTest.java b/itests/org.openhab.binding.mqtt.homeassistant.tests/src/main/java/org/openhab/binding/mqtt/homeassistant/HomeAssistantMQTTImplementationTest.java index 6e73c11675ede..fd5eb42251373 100644 --- a/itests/org.openhab.binding.mqtt.homeassistant.tests/src/main/java/org/openhab/binding/mqtt/homeassistant/HomeAssistantMQTTImplementationTest.java +++ b/itests/org.openhab.binding.mqtt.homeassistant.tests/src/main/java/org/openhab/binding/mqtt/homeassistant/HomeAssistantMQTTImplementationTest.java @@ -170,7 +170,7 @@ public void parseHATree() throws Exception { ScheduledExecutorService scheduler = new ScheduledThreadPoolExecutor(4); DiscoverComponents discover = spy(new DiscoverComponents(ThingChannelConstants.TEST_HOME_ASSISTANT_THING, - scheduler, channelStateUpdateListener, availabilityTracker, gson, jinjava, unitProvider, true)); + scheduler, channelStateUpdateListener, availabilityTracker, gson, jinjava, unitProvider)); // The DiscoverComponents object calls ComponentDiscovered callbacks. // In the following implementation we add the found component to the `haComponents` map