@@ -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
0 commit comments