Skip to content

Commit 6ee0158

Browse files
committed
clean
1 parent 3411c73 commit 6ee0158

3 files changed

Lines changed: 6 additions & 9 deletions

File tree

classes/transports/modbus_rtu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(self, settings : SectionProxy, protocolSettings : protocol_settings
4242

4343
address : int = settings.getint("address", 0)
4444
self.addresses = [address]
45-
45+
4646
# pymodbus compatability; unit was renamed to address
4747
if 'slave' in inspect.signature(ModbusSerialClient.read_holding_registers).parameters:
4848
self.pymodbus_slave_arg = 'slave'

classes/transports/mqtt.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,19 +167,16 @@ def write_data(self, data : dict[str, str], from_transport : transport_base):
167167
if info.rc == MQTT_ERR_NO_CONN:
168168
self.connected = False
169169

170-
171-
identifier = from_transport.device_model + "_" + from_transport.device_serial_number
172-
173170
if(self.json):
174171
# Serializing json
175172
json_object = json.dumps(data, indent=4)
176-
self.client.publish(self.base_topic+identifier, json_object, 0, properties=self.mqtt_properties)
173+
self.client.publish(self.base_topic+from_transport.device_identifier, json_object, 0, properties=self.mqtt_properties)
177174
else:
178175
for entry, val in data.items():
179176
if isinstance(val, float) and self.max_precision >= 0: #apply max_precision on mqtt transport
180177
val = round(val, self.max_precision)
181178

182-
self.client.publish(str(self.base_topic+identifier+'/'+entry).lower(), str(val))
179+
self.client.publish(str(self.base_topic+from_transport.device_identifier+'/'+entry).lower(), str(val))
183180

184181
def client_on_message(self, client, userdata, msg):
185182
""" The callback for when a PUBLISH message is received from the server. """
@@ -252,13 +249,11 @@ def mqtt_discovery(self, from_transport : transport_base):
252249
disc_payload['name'] = clean_name
253250
disc_payload['unique_id'] = "hotnoob_" + from_transport.device_serial_number + "_"+clean_name
254251

255-
identifier = from_transport.device_model + "_" + from_transport.device_serial_number
256-
257252
writePrefix = ""
258253
if from_transport.write_enabled and item.write_mode == WriteMode.WRITE:
259254
writePrefix = "" #home assistant doesnt like write prefix
260255

261-
disc_payload['state_topic'] = self.base_topic + identifier + writePrefix+ "/"+clean_name
256+
disc_payload['state_topic'] = self.base_topic + from_transport.device_identifier + writePrefix+ "/"+clean_name
262257

263258
if item.unit:
264259
disc_payload['unit_of_measurement'] = item.unit

classes/transports/transport_base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class transport_base:
1717
device_serial_number : str = ''
1818
device_manufacturer : str = 'hotnoob'
1919
device_model : str = 'hotnoob'
20+
device_identifier : str = 'hotnoob'
2021
bridge : str = ''
2122
write_enabled : bool = False
2223
max_precision : int = 2
@@ -67,6 +68,7 @@ def __init__(self, settings : 'SectionProxy', protocolSettings : 'protocol_setti
6768
else:
6869
self.write_enabled = settings.getboolean("write", self.write_enabled)
6970

71+
self.device_identifier = self.device_model + "_" + self.device_serial_number
7072

7173

7274
def init_bridge(self, from_transport : 'transport_base'):

0 commit comments

Comments
 (0)