]> git.basschouten.com Git - openhab-addons.git/commitdiff
[mqtt.homeassistant] remove channels for no-longer-configured components (#17447)
authorCody Cutrer <cody@cutrer.us>
Fri, 20 Sep 2024 06:52:05 +0000 (00:52 -0600)
committerGitHub <noreply@github.com>
Fri, 20 Sep 2024 06:52:05 +0000 (08:52 +0200)
Signed-off-by: Cody Cutrer <cody@cutrer.us>
bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/HaID.java
bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/handler/HomeAssistantThingHandler.java

index 829cbb54fe5091c60104a95b7f4dd1ed556f60e8..cd61ed8a85157cc55a36a165a36604dac2500ce1 100644 (file)
@@ -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:
index 8c19ce7efe3c158a2d10e9a7303b5c0cd65926db..1bfb1801214f08acdf591902222622dbf49a2acd 100644 (file)
@@ -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");