Skip to content

Commit

Permalink
Fix HA script topics (#2593)
Browse files Browse the repository at this point in the history
  • Loading branch information
unverbraucht authored Aug 11, 2023
1 parent fc727b3 commit ce794d7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions examples/rtl_433_mqtt_hass.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ def sanitize(text):
.replace(".", "_")
.replace("&", ""))

def rtl_433_device_info(data):
def rtl_433_device_info(data, topic_prefix):
"""Return rtl_433 device topic to subscribe to for a data element, based on the
rtl_433 device topic argument, as well as the device identifier"""

Expand All @@ -745,7 +745,7 @@ def rtl_433_device_info(data):

path = ''.join(list(filter(lambda item: item, path_elements)))
id = '-'.join(id_elements)
return (path, id)
return (f"{topic_prefix}/{path}", id)


def publish_config(mqttc, topic, model, object_id, mapping, value=None):
Expand Down Expand Up @@ -793,7 +793,7 @@ def publish_config(mqttc, topic, model, object_id, mapping, value=None):

return True

def bridge_event_to_hass(mqttc, topicprefix, data):
def bridge_event_to_hass(mqttc, topic_prefix, data):
"""Translate some rtl_433 sensor data to Home Assistant auto discovery."""

if "model" not in data:
Expand All @@ -806,7 +806,7 @@ def bridge_event_to_hass(mqttc, topicprefix, data):
skipped_keys = []
published_keys = []

base_topic, device_id = rtl_433_device_info(data)
base_topic, device_id = rtl_433_device_info(data, topic_prefix)
if not device_id:
# no unique device identifier
logging.warning("No suitable identifier found for model: ", model)
Expand Down

0 comments on commit ce794d7

Please sign in to comment.