mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Generate random MQTT client ID (#42934)
* Generate random MQTT client ID * Add comment * Apply suggestions from code review Co-authored-by: Franck Nijhof <git@frenck.dev> Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
parent
9d650245ee
commit
7f640c4a2e
@ -10,6 +10,7 @@ import os
|
||||
import ssl
|
||||
import time
|
||||
from typing import Any, Callable, List, Optional, Union
|
||||
import uuid
|
||||
|
||||
import attr
|
||||
import certifi
|
||||
@ -711,9 +712,10 @@ class MQTT:
|
||||
|
||||
client_id = self.conf.get(CONF_CLIENT_ID)
|
||||
if client_id is None:
|
||||
self._mqttc = mqtt.Client(protocol=proto)
|
||||
else:
|
||||
self._mqttc = mqtt.Client(client_id, protocol=proto)
|
||||
# PAHO MQTT relies on the MQTT server to generate random client IDs.
|
||||
# However, that feature is not mandatory so we generate our own.
|
||||
client_id = mqtt.base62(uuid.uuid4().int, padding=22)
|
||||
self._mqttc = mqtt.Client(client_id, protocol=proto)
|
||||
|
||||
# Enable logging
|
||||
self._mqttc.enable_logger()
|
||||
|
Loading…
x
Reference in New Issue
Block a user