22
33import base64
44import logging
5- import secrets
65import threading
6+ import uuid
77from asyncio import Lock
88from typing import Any
99from urllib .parse import urlparse
@@ -49,16 +49,12 @@ def __init__(self, user_data: UserData, devices_info: dict[str, RoborockDeviceIn
4949 self ._mqtt_password = rriot .s
5050 self ._hashed_password = md5hex (self ._mqtt_password + ":" + rriot .k )[16 :]
5151 super ().username_pw_set (self ._hashed_user , self ._hashed_password )
52- self ._seq = 1
53- self ._random = 4711
54- self ._id_counter = 2
55- self ._salt = "TXdfu$jyZ#TZHsg4"
5652 self ._endpoint = base64 .b64encode (md5bin (rriot .k )[8 :14 ]).decode ()
57- self ._nonce = secrets .token_bytes (16 )
5853 self ._waiting_queue : dict [int , RoborockQueue ] = {}
5954 self ._mutex = Lock ()
6055 self ._last_device_msg_in = mqtt .time_func ()
6156 self ._last_disconnection = mqtt .time_func ()
57+ self .update_client_id ()
6258
6359 def __del__ (self ) -> None :
6460 self .sync_disconnect ()
@@ -102,6 +98,8 @@ async def on_disconnect(self, _client: mqtt.Client, _, rc, __=None) -> None:
10298 try :
10399 self ._last_disconnection = mqtt .time_func ()
104100 message = f"Roborock mqtt client disconnected (rc: { rc } )"
101+ if rc == mqtt .MQTT_ERR_PROTOCOL :
102+ self .update_client_id ()
105103 _LOGGER .warning (message )
106104 connection_queue = self ._waiting_queue .get (1 )
107105 if connection_queue :
@@ -111,6 +109,9 @@ async def on_disconnect(self, _client: mqtt.Client, _, rc, __=None) -> None:
111109 except Exception as ex :
112110 _LOGGER .exception (ex )
113111
112+ def update_client_id (self ):
113+ self ._client_id = mqtt .base62 (uuid .uuid4 ().int , padding = 22 )
114+
114115 @run_in_executor ()
115116 async def _async_check_keepalive (self ) -> None :
116117 async with self ._mutex :
0 commit comments