From f9f8894365eeb798919410ac3933f8a3146fa661 Mon Sep 17 00:00:00 2001 From: saveriol Date: Mon, 16 Sep 2024 14:33:41 +0200 Subject: [PATCH 1/2] Revert host to name in mqtt topic --- HADiscovery.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/HADiscovery.py b/HADiscovery.py index f4d961f..e1ee8ab 100644 --- a/HADiscovery.py +++ b/HADiscovery.py @@ -163,8 +163,7 @@ def augment_device_features(features): def publish_ha_discovery(device, client, mqtt_topic): print(f"{now()} Publishing HA discovery for {device}") - device_ident = device["host"] - device_name = device["name"] + device_ident = device["name"] device_description = device.get("description", {}) version_parts = filter( @@ -174,7 +173,7 @@ def publish_ha_discovery(device, client, mqtt_topic): device_info = { "identifiers": [device_ident], - "name": device_name, + "name": device_ident, "manufacturer": device_description.get("brand"), "model": device_description.get("model"), "sw_version": ".".join(version_parts), From 1c9d897f89e9c9481d498055a52b5884ef9f6eba Mon Sep 17 00:00:00 2001 From: saveriol Date: Mon, 16 Sep 2024 14:35:32 +0200 Subject: [PATCH 2/2] Revert host to name in mqtt topic --- hc2mqtt.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hc2mqtt.py b/hc2mqtt.py index 8d4f1d2..669245c 100755 --- a/hc2mqtt.py +++ b/hc2mqtt.py @@ -57,6 +57,7 @@ def hc2mqtt( client.publish(f"{mqtt_prefix}LWT", payload="online", qos=0, retain=True) # Re-subscribe to all device topics on reconnection for device in devices: + mqtt_topic = f"{mqtt_prefix}{device['name']}" mqtt_set_topic = f"{mqtt_prefix}{device['name']}/set" print(now(), device["name"], f"set topic: {mqtt_set_topic}") client.subscribe(mqtt_set_topic) @@ -151,7 +152,7 @@ def hc2mqtt( client.connect(host=mqtt_host, port=mqtt_port, keepalive=70) for device in devices: - mqtt_topic = mqtt_prefix + device["host"] + mqtt_topic = mqtt_prefix + device["name"] thread = Thread( target=client_connect, args=(client, device, mqtt_topic, domain_suffix, debug) )