44import logging
55import threading
66import time
7- import uuid
87from collections import defaultdict
98from datetime import datetime
109from typing import Any , Callable , Dict , List , Optional , Tuple , Union , cast
2019 DISCOVERY_TIMEOUT_IN_SEC ,
2120 FRAGMENT_DEVICE_TYPE ,
2221 FRAGMENT_STATE ,
23- MQTT_CLIENT_ID ,
2422 MQTT_HOST ,
2523 MQTT_PASSWORD ,
2624 MQTT_PORT ,
@@ -68,10 +66,12 @@ def __init__(
6866 if _t not in MQTT_TRANSPORTS :
6967 raise Exception
7068
71- if (client_id := config .get (MQTT_CLIENT_ID )) is None :
72- client_id = mqtt .base62 (uuid .uuid4 ().int , padding = 22 )
73-
74- self .__client = mqtt .Client (client_id , protocol = self .__proto , transport = _t )
69+ self .__client = mqtt .Client (
70+ callback_api_version = mqtt .CallbackAPIVersion .VERSION2 ,
71+ protocol = self .__proto ,
72+ transport = _t ,
73+ reconnect_on_failure = True ,
74+ )
7575
7676 self .__client .on_connect = self .__on_connect
7777 self .__client .on_subscribe = self .__on_subscribe
@@ -270,6 +270,7 @@ def __on_disconnect(
270270 self ,
271271 client : mqtt .Client , # pylint: disable=unused-argument
272272 userdata : Any , # pylint: disable=unused-argument
273+ disconnect_flags : dict ,
273274 reason_code : int ,
274275 properties : Optional [Properties ] = None ,
275276 ) -> None :
@@ -278,6 +279,7 @@ def __on_disconnect(
278279 Args:
279280 client (mqtt.Client): instance of the mqtt client
280281 userdata (Any): user's data
282+ disconnect_flags (dict): response flags sent by the broker
281283 reason_code (int): reason code for disconnection
282284 properties (Optional[Properties]): MQTT v5 properties
283285 """
@@ -298,7 +300,7 @@ def __on_connect(
298300 self ,
299301 client : mqtt .Client , # pylint: disable=unused-argument
300302 userdata : Any , # pylint: disable=unused-argument
301- flags : dict ,
303+ connect_flags : dict ,
302304 reason_code : int ,
303305 properties : Optional [Properties ] = None , # pylint: disable=unused-argument
304306 ) -> None :
@@ -307,7 +309,7 @@ def __on_connect(
307309 Args:
308310 client (mqtt.Client): instance of mqtt client
309311 userdata (Any): user data as set in Client() or user_data_set()
310- flags (dict): response flags sent by the broker
312+ connect_flags (dict): response flags sent by the broker
311313 reason_code (int): the connection result
312314 properties (Optional[Properties]): the MQTT v5 properties returned from the broker
313315 """
@@ -425,7 +427,7 @@ def __on_subscribe(
425427 client : mqtt .Client , # pylint: disable=unused-argument
426428 userdata : Any , # pylint: disable=unused-argument
427429 mid : int , # pylint: disable=unused-argument
428- granted_qos : List [int ], # pylint: disable=unused-argument
430+ reason_code_list : List [int ], # pylint: disable=unused-argument
429431 properties : Optional [Any ] = None , # pylint: disable=unused-argument
430432 ) -> None :
431433 """Callback for subscribe function."""
@@ -448,7 +450,7 @@ def __on_unsubscribe(
448450 userdata : Any ,
449451 mid : int ,
450452 properties : Optional [Any ] = None ,
451- reasoncodes : Optional [List [int ]] = None ,
453+ reason_code_list : Optional [List [int ]] = None ,
452454 ) -> None :
453455 """Callback for when the client receives an UNSUBACK response from the broker."""
454456 topic_to_remove = None
0 commit comments