Fix small issue related to topic prefix (#18512)
Fix expansion of topic prefix when discovery message contains non string-type items.
This commit is contained in:
parent
ab8c127a4a
commit
7e702d3caa
1 changed files with 5 additions and 4 deletions
|
@ -202,10 +202,11 @@ async def async_start(hass: HomeAssistantType, discovery_topic, hass_config,
|
|||
if TOPIC_BASE in payload:
|
||||
base = payload[TOPIC_BASE]
|
||||
for key, value in payload.items():
|
||||
if value[0] == TOPIC_BASE and key.endswith('_topic'):
|
||||
payload[key] = "{}{}".format(base, value[1:])
|
||||
if value[-1] == TOPIC_BASE and key.endswith('_topic'):
|
||||
payload[key] = "{}{}".format(value[:-1], base)
|
||||
if isinstance(value, str):
|
||||
if value[0] == TOPIC_BASE and key.endswith('_topic'):
|
||||
payload[key] = "{}{}".format(base, value[1:])
|
||||
if value[-1] == TOPIC_BASE and key.endswith('_topic'):
|
||||
payload[key] = "{}{}".format(value[:-1], base)
|
||||
|
||||
# If present, the node_id will be included in the discovered object id
|
||||
discovery_id = '_'.join((node_id, object_id)) if node_id else object_id
|
||||
|
|
Loading…
Add table
Reference in a new issue