mqtt: add support for a user configured client id

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2024-07-22 13:55:33 -04:00
parent 5c62149fc4
commit b8ba6c0d2b
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
1 changed files with 4 additions and 2 deletions

View File

@ -352,11 +352,13 @@ class MQTTClient(APITransport):
"between 0 and 2")
self.publish_split_status = \
config.getboolean("publish_split_status", False)
client_id: Optional[str] = config.get("client_id", None)
if PAHO_MQTT_VERSION < (2, 0):
self.client = ExtPahoClient(protocol=self.protocol)
self.client = ExtPahoClient(client_id, protocol=self.protocol)
else:
self.client = ExtPahoClient(
paho_mqtt.CallbackAPIVersion.VERSION1, protocol=self.protocol
paho_mqtt.CallbackAPIVersion.VERSION1, client_id,
protocol=self.protocol
)
self.client.on_connect = self._on_connect
self.client.on_message = self._on_message