From b77458dca7b092ed0b7740240d4fe72aebb3415f Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Fri, 20 Sep 2024 00:52:05 -0600 Subject: [PATCH] [mqtt.homeassistant] remove channels for no-longer-configured components (#17447) Signed-off-by: Cody Cutrer --- .../binding/mqtt/homeassistant/internal/HaID.java | 7 +++++++ .../internal/handler/HomeAssistantThingHandler.java | 12 +++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) 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 829cbb54fe5..cd61ed8a851 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 @@ -214,6 +214,13 @@ public class HaID { return UIDUtils.encode(result); } + /** + * Return the topic for this component, without /config + */ + public String getTopic() { + return topic; + } + /** * Return a topic, which can be used for a mqtt subscription. * Defined values for suffix are: 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 8c19ce7efe3..1bfb1801214 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 @@ -150,8 +150,18 @@ public class HomeAssistantThingHandler extends AbstractMQTTThingHandler // Already restored component? @Nullable AbstractComponent component = haComponents.get(groupID); - + if (component != null) { + continue; + } HaID haID = HaID.fromConfig(config.basetopic, channel.getConfiguration()); + + if (!config.topics.contains(haID.getTopic())) { + // don't add a component for this channel that isn't configured on the thing + // anymore + // It will disappear from the thing when the thing type is updated below + continue; + } + discoveryHomeAssistantIDs.add(haID); ThingUID thingUID = channel.getUID().getThingUID(); String channelConfigurationJSON = (String) channel.getConfiguration().get("config");