From 515e0ecbded377074820a8d7ca42c5cd17cc3c59 Mon Sep 17 00:00:00 2001 From: Kevin Read Date: Fri, 11 Aug 2023 14:33:32 +0200 Subject: [PATCH] Fix HA script remove device name from entities (#2594) * Fixes #2591: Remove device name from entity name, use more readable entity names * Remove changes that slipped in from https://github.com/merbanan/rtl_433/pull/2593 --- examples/rtl_433_mqtt_hass.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/rtl_433_mqtt_hass.py b/examples/rtl_433_mqtt_hass.py index 05d6d83b00..6b06c73ac7 100755 --- a/examples/rtl_433_mqtt_hass.py +++ b/examples/rtl_433_mqtt_hass.py @@ -748,7 +748,7 @@ def rtl_433_device_info(data, topic_prefix): return (f"{topic_prefix}/{path}", id) -def publish_config(mqttc, topic, model, object_id, mapping, value=None): +def publish_config(mqttc, topic, model, object_id, mapping, key=None): """Publish Home Assistant auto discovery data.""" global discovery_timeouts @@ -776,9 +776,10 @@ def publish_config(mqttc, topic, model, object_id, mapping, value=None): config["topic"] = topic config["platform"] = 'mqtt' else: + readable_name = mapping["config"]["name"] if "name" in mapping["config"] else key config["state_topic"] = topic config["unique_id"] = object_name - config["name"] = object_name + config["name"] = readable_name config["device"] = { "identifiers": [object_id], "name": object_id, "model": model, "manufacturer": "rtl_433" } if args.force_update: @@ -822,7 +823,7 @@ def bridge_event_to_hass(mqttc, topic_prefix, data): if key in mappings: # topic = "/".join([topicprefix,"devices",model,instance,key]) topic = "/".join([base_topic, key]) - if publish_config(mqttc, topic, model, device_id, mappings[key]): + if publish_config(mqttc, topic, model, device_id, mappings[key], key): published_keys.append(key) else: if key not in SKIP_KEYS: @@ -831,7 +832,7 @@ def bridge_event_to_hass(mqttc, topic_prefix, data): if "secret_knock" in data.keys(): for m in secret_knock_mappings: topic = "/".join([base_topic, "secret_knock"]) - if publish_config(mqttc, topic, model, device_id, m): + if publish_config(mqttc, topic, model, device_id, m, "secret_knock"): published_keys.append("secret_knock") if published_keys: