[mqtt.homeassistant] remove channels for no-longer-configured components (#17447)

Signed-off-by: Cody Cutrer <cody@cutrer.us>
This commit is contained in:
Cody Cutrer 2024-09-20 00:52:05 -06:00 committed by GitHub
parent 19c18be297
commit b77458dca7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 1 deletions

View 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:

View 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");