Skip to content

Commit

Permalink
Fix HA script remove device name from entities (#2594)
Browse files Browse the repository at this point in the history
* Fixes #2591: Remove device name from entity name, use more readable entity names
* Remove changes that slipped in from  #2593
  • Loading branch information
unverbraucht authored Aug 11, 2023
1 parent ce794d7 commit 9e0fb41
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions examples/rtl_433_mqtt_hass.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 9e0fb41

Please sign in to comment.