Skip to content

Commit 6159412

Browse files
fix: fix cloud_api
1 parent 7579ad5 commit 6159412

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

roborock/api.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ class RoborockClient:
8787

8888
def __init__(self, endpoint: str, devices_info: dict[str, RoborockDeviceInfo]) -> None:
8989
self.devices_info = devices_info
90-
self._salt = "TXdfu$jyZ#TZHsg4"
9190
self._endpoint = endpoint
9291
self._nonce = secrets.token_bytes(16)
9392
self._waiting_queue: dict[int, RoborockQueue] = {}

roborock/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ def reload(self):
2626
with open(self.roborock_file, 'r') as f:
2727
data = json.load(f)
2828
if data:
29-
self._login_data = LoginData(data)
29+
self._login_data = LoginData.from_dict(data)
3030

3131
def update(self, login_data: LoginData):
32-
data = json.dumps(login_data, default=vars)
32+
data = json.dumps(login_data.as_dict(), default=vars)
3333
with open(self.roborock_file, 'w') as f:
3434
f.write(data)
3535
self.reload()

roborock/cloud_api.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import base64
44
import logging
5-
import secrets
65
import threading
6+
import uuid
77
from asyncio import Lock
88
from typing import Any
99
from 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

Comments
 (0)