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:
emontnemery 2018-11-19 09:59:07 +01:00 committed by Paulus Schoutsen
parent ab8c127a4a
commit 7e702d3caa

View file

@ -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