Skip to content

Commit 07b731f

Browse files
committed
PLG: add connections attribute to mqtt #1681
1 parent 7f5c001 commit 07b731f

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

  • front/plugins/_publisher_mqtt

front/plugins/_publisher_mqtt/mqtt.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,20 @@ def initialize_message(self):
150150
"device_class": "timestamp"
151151
})
152152

153+
# prepare mac for "connections"
154+
if self.mac != "":
155+
connections_snippet = [
156+
["mac", self.mac]
157+
]
158+
else:
159+
connections_snippet = []
160+
153161
# Handle 'binary_sensor' or 'sensor' types
154162
if self.sensorType in ['binary_sensor', 'sensor']:
155163
self.topic = f'homeassistant/{self.sensorType}/{self.deviceId}/{self.sensorName}/config'
156164
self.state_topic = f'{topic_root}/{self.sensorType}/{self.deviceId}/state'
157165
self.unique_id = f'{self.deviceId}_sensor_{self.sensorName}'
158166

159-
if self.mac != "":
160-
connections_snippet = [
161-
["mac", self.mac]
162-
]
163-
else:
164-
connections_snippet = []
165-
166167
# Update the message dictionary, expanding it without overwriting
167168
self.message.update({
168169
"name": self.sensorName,
@@ -172,8 +173,7 @@ def initialize_message(self):
172173
"device": {
173174
"identifiers": [f"{self.deviceId}_sensor"],
174175
"manufacturer": "NetAlertX",
175-
"name": self.deviceName,
176-
"connections": connections_snippet
176+
"name": self.deviceName
177177
},
178178
"icon": f'mdi:{self.icon}'
179179
})
@@ -198,7 +198,8 @@ def initialize_message(self):
198198
"identifiers": [f"{self.deviceId}_sensor", self.unique_id],
199199
"manufacturer": "NetAlertX",
200200
"model": self.model or "Unknown", # Use model if available, else set to 'Unknown'
201-
"name": self.deviceName
201+
"name": self.deviceName,
202+
"connections": connections_snippet
202203
}
203204
}
204205

0 commit comments

Comments
 (0)