Skip to content

Commit

Permalink
[mqtt.homeassistant] remove channels for no-longer-configured compone…
Browse files Browse the repository at this point in the history
…nts (#17447)

Signed-off-by: Cody Cutrer <[email protected]>
  • Loading branch information
ccutrer committed Sep 20, 2024
1 parent 19c18be commit b77458d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ public String getGroupId(@Nullable final String uniqueId, boolean newStyleChanne
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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,18 @@ public void initialize() {
// 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");
Expand Down

0 comments on commit b77458d

Please sign in to comment.