Skip to content

Commit 493ed4b

Browse files
fix: changing code mappings
1 parent 1ced9e9 commit 493ed4b

File tree

7 files changed

+212
-177
lines changed

7 files changed

+212
-177
lines changed

roborock/api.py

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
from roborock.exceptions import (
2424
RoborockException, RoborockTimeout, VacuumError,
2525
)
26-
from .code_mappings import RoborockDockType, \
27-
STATE_CODE_TO_STATUS
26+
from .code_mappings import RoborockDockTypeCode
2827
from .containers import (
2928
UserData,
3029
Status,
@@ -131,15 +130,6 @@ async def on_message(self, messages: list[RoborockMessage]) -> None:
131130
await queue.async_put(
132131
(result, None), timeout=QUEUE_TIMEOUT
133132
)
134-
elif data_point_number == "121":
135-
status = STATE_CODE_TO_STATUS.get(data_point)
136-
_LOGGER.debug(f"Status updated to {status}")
137-
for listener in self._status_listeners:
138-
listener(data.seq, status)
139-
else:
140-
_LOGGER.debug(
141-
f"Unknown data point number received {data_point_number} with {data_point}"
142-
)
143133
elif protocol == 301:
144134
payload = data.payload[0:24]
145135
[endpoint, _, request_id, _] = struct.unpack("<15sBH6s", payload)
@@ -205,13 +195,13 @@ async def send_command(
205195
async def get_status(self, device_id: str) -> Status:
206196
status = await self.send_command(device_id, RoborockCommand.GET_STATUS)
207197
if isinstance(status, dict):
208-
return Status(status)
198+
return Status.from_dict(status)
209199

210200
async def get_dnd_timer(self, device_id: str) -> DNDTimer:
211201
try:
212202
dnd_timer = await self.send_command(device_id, RoborockCommand.GET_DND_TIMER)
213203
if isinstance(dnd_timer, dict):
214-
return DNDTimer(dnd_timer)
204+
return DNDTimer.from_dict(dnd_timer)
215205
except RoborockTimeout as e:
216206
_LOGGER.error(e)
217207

@@ -221,9 +211,9 @@ async def get_clean_summary(self, device_id: str) -> CleanSummary:
221211
device_id, RoborockCommand.GET_CLEAN_SUMMARY
222212
)
223213
if isinstance(clean_summary, dict):
224-
return CleanSummary(clean_summary)
214+
return CleanSummary.from_dict(clean_summary)
225215
elif isinstance(clean_summary, bytes):
226-
return CleanSummary({"clean_time": clean_summary})
216+
return CleanSummary(clean_time=int.from_bytes(clean_summary, 'big'))
227217
except RoborockTimeout as e:
228218
_LOGGER.error(e)
229219

@@ -233,46 +223,46 @@ async def get_clean_record(self, device_id: str, record_id: int) -> CleanRecord:
233223
device_id, RoborockCommand.GET_CLEAN_RECORD, [record_id]
234224
)
235225
if isinstance(clean_record, dict):
236-
return CleanRecord(clean_record)
226+
return CleanRecord.from_dict(clean_record)
237227
except RoborockTimeout as e:
238228
_LOGGER.error(e)
239229

240230
async def get_consumable(self, device_id: str) -> Consumable:
241231
try:
242232
consumable = await self.send_command(device_id, RoborockCommand.GET_CONSUMABLE)
243233
if isinstance(consumable, dict):
244-
return Consumable(consumable)
234+
return Consumable.from_dict(consumable)
245235
except RoborockTimeout as e:
246236
_LOGGER.error(e)
247237

248238
async def get_wash_towel_mode(self, device_id: str) -> WashTowelMode:
249239
try:
250240
washing_mode = await self.send_command(device_id, RoborockCommand.GET_WASH_TOWEL_MODE)
251241
if isinstance(washing_mode, dict):
252-
return WashTowelMode(washing_mode)
242+
return WashTowelMode.from_dict(washing_mode)
253243
except RoborockTimeout as e:
254244
_LOGGER.error(e)
255245

256246
async def get_dust_collection_mode(self, device_id: str) -> DustCollectionMode:
257247
try:
258248
dust_collection = await self.send_command(device_id, RoborockCommand.GET_DUST_COLLECTION_MODE)
259249
if isinstance(dust_collection, dict):
260-
return DustCollectionMode(dust_collection)
250+
return DustCollectionMode.from_dict(dust_collection)
261251
except RoborockTimeout as e:
262252
_LOGGER.error(e)
263253

264254
async def get_smart_wash_params(self, device_id: str) -> SmartWashParams:
265255
try:
266256
mop_wash_mode = await self.send_command(device_id, RoborockCommand.GET_SMART_WASH_PARAMS)
267257
if isinstance(mop_wash_mode, dict):
268-
return SmartWashParams(mop_wash_mode)
258+
return SmartWashParams.from_dict(mop_wash_mode)
269259
except RoborockTimeout as e:
270260
_LOGGER.error(e)
271261

272-
async def get_dock_summary(self, device_id: str, dock_type: RoborockDockType) -> RoborockDockSummary:
262+
async def get_dock_summary(self, device_id: str, dock_type: RoborockDockTypeCode) -> RoborockDockSummary:
273263
try:
274264
commands = [self.get_dust_collection_mode(device_id)]
275-
if dock_type == RoborockDockType.EMPTY_WASH_FILL_DOCK:
265+
if dock_type == RoborockDockTypeCode.EMPTY_WASH_FILL_DOCK:
276266
commands += [self.get_wash_towel_mode(device_id), self.get_smart_wash_params(device_id)]
277267
[
278268
dust_collection_mode,
@@ -302,7 +292,7 @@ async def get_prop(self, device_id: str) -> RoborockDeviceProp | None:
302292
device_id, clean_summary.records[0]
303293
)
304294
dock_summary = None
305-
if status and status.dock_type != RoborockDockType.NO_DOCK:
295+
if status and status.dock_type != RoborockDockTypeCode.NO_DOCK:
306296
dock_summary = await self.get_dock_summary(device_id, status.dock_type)
307297
if any([status, dnd_timer, clean_summary, consumable]):
308298
return RoborockDeviceProp(
@@ -316,15 +306,15 @@ async def get_multi_maps_list(self, device_id) -> MultiMapsList:
316306
device_id, RoborockCommand.GET_MULTI_MAPS_LIST
317307
)
318308
if isinstance(multi_maps_list, dict):
319-
return MultiMapsList(multi_maps_list)
309+
return MultiMapsList.from_dict(multi_maps_list)
320310
except RoborockTimeout as e:
321311
_LOGGER.error(e)
322312

323313
async def get_networking(self, device_id) -> NetworkInfo:
324314
try:
325315
networking_info = await self.send_command(device_id, RoborockCommand.GET_NETWORK_INFO)
326316
if isinstance(networking_info, dict):
327-
return NetworkInfo(networking_info)
317+
return NetworkInfo.from_dict(networking_info)
328318
except RoborockTimeout as e:
329319
_LOGGER.error(e)
330320

@@ -390,7 +380,7 @@ async def pass_login(self, password: str) -> UserData:
390380

391381
if login_response.get("code") != 200:
392382
raise RoborockException(login_response.get("msg"))
393-
return UserData(login_response.get("data"))
383+
return UserData.from_dict(login_response.get("data"))
394384

395385
async def code_login(self, code) -> UserData:
396386
base_url = await self._get_base_url()
@@ -409,7 +399,7 @@ async def code_login(self, code) -> UserData:
409399

410400
if login_response.get("code") != 200:
411401
raise RoborockException(login_response.get("msg"))
412-
return UserData(login_response.get("data"))
402+
return UserData.from_dict(login_response.get("data"))
413403

414404
async def get_home_data(self, user_data: UserData) -> HomeData:
415405
base_url = await self._get_base_url()
@@ -430,8 +420,8 @@ async def get_home_data(self, user_data: UserData) -> HomeData:
430420
nonce = secrets.token_urlsafe(6)
431421
prestr = ":".join(
432422
[
433-
rriot.user,
434-
rriot.password,
423+
rriot.u,
424+
rriot.s,
435425
nonce,
436426
str(timestamp),
437427
hashlib.md5(("/user/homes/" + str(home_id)).encode()).hexdigest(),
@@ -440,17 +430,17 @@ async def get_home_data(self, user_data: UserData) -> HomeData:
440430
]
441431
)
442432
mac = base64.b64encode(
443-
hmac.new(rriot.h_unknown.encode(), prestr.encode(), hashlib.sha256).digest()
433+
hmac.new(rriot.h.encode(), prestr.encode(), hashlib.sha256).digest()
444434
).decode()
445435
home_request = PreparedRequest(
446-
rriot.reference.api,
436+
rriot.r.a,
447437
{
448-
"Authorization": f'Hawk id="{rriot.user}", s="{rriot.password}", ts="{timestamp}", nonce="{nonce}", '
438+
"Authorization": f'Hawk id="{rriot.u}", s="{rriot.s}", ts="{timestamp}", nonce="{nonce}", '
449439
f'mac="{mac}"',
450440
},
451441
)
452442
home_response = await home_request.request("get", "/user/homes/" + str(home_id))
453443
if not home_response.get("success"):
454444
raise RoborockException(home_response)
455445
home_data = home_response.get("result")
456-
return HomeData(home_data)
446+
return HomeData.from_dict(home_data)

roborock/cloud_api.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,25 @@ class RoborockMqttClient(RoborockClient, mqtt.Client):
3535

3636
def __init__(self, user_data: UserData, devices_info: dict[str, RoborockDeviceInfo]) -> None:
3737
rriot = user_data.rriot
38-
endpoint = base64.b64encode(md5bin(rriot.endpoint)[8:14]).decode()
38+
endpoint = base64.b64encode(md5bin(rriot.k)[8:14]).decode()
3939
RoborockClient.__init__(self, endpoint, devices_info)
4040
mqtt.Client.__init__(self, protocol=mqtt.MQTTv5)
41-
self._mqtt_user = rriot.user
42-
self._hashed_user = md5hex(self._mqtt_user + ":" + rriot.endpoint)[2:10]
43-
url = urlparse(rriot.reference.mqtt)
41+
self._mqtt_user = rriot.u
42+
self._hashed_user = md5hex(self._mqtt_user + ":" + rriot.k)[2:10]
43+
url = urlparse(rriot.r.m)
4444
self._mqtt_host = url.hostname
4545
self._mqtt_port = url.port
4646
self._mqtt_ssl = url.scheme == "ssl"
4747
if self._mqtt_ssl:
4848
super().tls_set()
49-
self._mqtt_password = rriot.password
50-
self._hashed_password = md5hex(self._mqtt_password + ":" + rriot.endpoint)[16:]
49+
self._mqtt_password = rriot.s
50+
self._hashed_password = md5hex(self._mqtt_password + ":" + rriot.k)[16:]
5151
super().username_pw_set(self._hashed_user, self._hashed_password)
5252
self._seq = 1
5353
self._random = 4711
5454
self._id_counter = 2
5555
self._salt = "TXdfu$jyZ#TZHsg4"
56-
self._endpoint = base64.b64encode(md5bin(rriot.endpoint)[8:14]).decode()
56+
self._endpoint = base64.b64encode(md5bin(rriot.k)[8:14]).decode()
5757
self._nonce = secrets.token_bytes(16)
5858
self._waiting_queue: dict[int, RoborockQueue] = {}
5959
self._mutex = Lock()

0 commit comments

Comments
 (0)