Skip to content

Commit 4ba8555

Browse files
committed
add serial / id to other mqtt topics
1 parent fbad810 commit 4ba8555

6 files changed

Lines changed: 878 additions & 5 deletions

classes/transports/mqtt.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def connect(self):
110110
def exit_handler(self):
111111
'''on exit handler'''
112112
self._log.warning("MQTT Exiting...")
113-
self.client.publish( self.base_topic + "/availability","offline")
113+
self.client.publish( self.base_topic + '/' + self.device_identifier + "/availability","offline")
114114
return
115115

116116
def mqtt_reconnect(self):
@@ -163,7 +163,7 @@ def write_data(self, data : dict[str, str], from_transport : transport_base):
163163
self._log.info(f"write data from [{from_transport.transport_name}] to mqtt transport")
164164
self._log.info(data)
165165
#have to send this every loop, because mqtt doesnt disconnect when HA restarts. HA bug.
166-
info = self.client.publish(self.base_topic + "/availability","online", qos=0,retain=True)
166+
info = self.client.publish(self.base_topic + '/' + from_transport.device_identifier + "/availability","online", qos=0,retain=True)
167167
if info.rc == MQTT_ERR_NO_CONN:
168168
self.connected = False
169169

@@ -196,7 +196,7 @@ def init_bridge(self, from_transport : transport_base):
196196
for entry in from_transport.protocolSettings.get_registry_map(Registry_Type.HOLDING):
197197
if entry.write_mode == WriteMode.WRITE or entry.write_mode == WriteMode.WRITEONLY:
198198
#__write_topics
199-
topic : str = self.base_topic + "/write/" + entry.variable_name.lower().replace(' ', '_')
199+
topic : str = self.base_topic + '/'+ from_transport.device_identifier + "/write/" + entry.variable_name.lower().replace(' ', '_')
200200
self.__write_topics[topic] = entry
201201
self.client.subscribe(topic)
202202

@@ -207,7 +207,7 @@ def mqtt_discovery(self, from_transport : transport_base):
207207
self._log.info("Publishing HA Discovery Topics...")
208208

209209
disc_payload = {}
210-
disc_payload['availability_topic'] = self.base_topic + "/availability"
210+
disc_payload['availability_topic'] = self.base_topic + '/' + from_transport.device_identifier + "/availability"
211211

212212
device = {}
213213
device['manufacturer'] = from_transport.device_manufacturer
@@ -247,7 +247,7 @@ def mqtt_discovery(self, from_transport : transport_base):
247247

248248
#device['sw_version'] = bms_version
249249
disc_payload = {}
250-
disc_payload['availability_topic'] = self.base_topic + "/availability"
250+
disc_payload['availability_topic'] = self.base_topic + '/' + from_transport.device_identifier + "/availability"
251251
disc_payload['device'] = device
252252
disc_payload['name'] = clean_name
253253
disc_payload['unique_id'] = "hotnoob_" + from_transport.device_serial_number + "_"+clean_name
Binary file not shown.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
variable name,data type,register,documented name,description,write,values,unit
2+
,,0x0001 ,MCU Software version ,,R,,
3+
,,x0002,Gauge Version ,,,,
4+
,ASCII,x0003-x0004,Gauge FR Version ,,,,
5+
,6bit,x0005,Date Second,,,,
6+
,6bit,x0005.b6,Date Minute,,,,
7+
,6bit,x0005.b12,Date Hour,,,,
8+
,6bit,x0006,Date Day,,,,
9+
,6bit,x0006.b6,Date Month,,,,
10+
,6bit,x0006.b12,Date Year,,,,

0 commit comments

Comments
 (0)