2
2
3
3
import base64
4
4
import logging
5
- import secrets
6
5
import threading
6
+ import uuid
7
7
from asyncio import Lock
8
8
from typing import Any
9
9
from urllib .parse import urlparse
@@ -49,16 +49,12 @@ def __init__(self, user_data: UserData, devices_info: dict[str, RoborockDeviceIn
49
49
self ._mqtt_password = rriot .s
50
50
self ._hashed_password = md5hex (self ._mqtt_password + ":" + rriot .k )[16 :]
51
51
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"
56
52
self ._endpoint = base64 .b64encode (md5bin (rriot .k )[8 :14 ]).decode ()
57
- self ._nonce = secrets .token_bytes (16 )
58
53
self ._waiting_queue : dict [int , RoborockQueue ] = {}
59
54
self ._mutex = Lock ()
60
55
self ._last_device_msg_in = mqtt .time_func ()
61
56
self ._last_disconnection = mqtt .time_func ()
57
+ self .update_client_id ()
62
58
63
59
def __del__ (self ) -> None :
64
60
self .sync_disconnect ()
@@ -102,6 +98,8 @@ async def on_disconnect(self, _client: mqtt.Client, _, rc, __=None) -> None:
102
98
try :
103
99
self ._last_disconnection = mqtt .time_func ()
104
100
message = f"Roborock mqtt client disconnected (rc: { rc } )"
101
+ if rc == mqtt .MQTT_ERR_PROTOCOL :
102
+ self .update_client_id ()
105
103
_LOGGER .warning (message )
106
104
connection_queue = self ._waiting_queue .get (1 )
107
105
if connection_queue :
@@ -111,6 +109,9 @@ async def on_disconnect(self, _client: mqtt.Client, _, rc, __=None) -> None:
111
109
except Exception as ex :
112
110
_LOGGER .exception (ex )
113
111
112
+ def update_client_id (self ):
113
+ self ._client_id = mqtt .base62 (uuid .uuid4 ().int , padding = 22 )
114
+
114
115
@run_in_executor ()
115
116
async def _async_check_keepalive (self ) -> None :
116
117
async with self ._mutex :
0 commit comments