23
23
from roborock .exceptions import (
24
24
RoborockException , RoborockTimeout , VacuumError ,
25
25
)
26
- from .code_mappings import RoborockDockType , \
27
- STATE_CODE_TO_STATUS
26
+ from .code_mappings import RoborockDockTypeCode
28
27
from .containers import (
29
28
UserData ,
30
29
Status ,
@@ -131,15 +130,6 @@ async def on_message(self, messages: list[RoborockMessage]) -> None:
131
130
await queue .async_put (
132
131
(result , None ), timeout = QUEUE_TIMEOUT
133
132
)
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
- )
143
133
elif protocol == 301 :
144
134
payload = data .payload [0 :24 ]
145
135
[endpoint , _ , request_id , _ ] = struct .unpack ("<15sBH6s" , payload )
@@ -205,13 +195,13 @@ async def send_command(
205
195
async def get_status (self , device_id : str ) -> Status :
206
196
status = await self .send_command (device_id , RoborockCommand .GET_STATUS )
207
197
if isinstance (status , dict ):
208
- return Status (status )
198
+ return Status . from_dict (status )
209
199
210
200
async def get_dnd_timer (self , device_id : str ) -> DNDTimer :
211
201
try :
212
202
dnd_timer = await self .send_command (device_id , RoborockCommand .GET_DND_TIMER )
213
203
if isinstance (dnd_timer , dict ):
214
- return DNDTimer (dnd_timer )
204
+ return DNDTimer . from_dict (dnd_timer )
215
205
except RoborockTimeout as e :
216
206
_LOGGER .error (e )
217
207
@@ -221,9 +211,9 @@ async def get_clean_summary(self, device_id: str) -> CleanSummary:
221
211
device_id , RoborockCommand .GET_CLEAN_SUMMARY
222
212
)
223
213
if isinstance (clean_summary , dict ):
224
- return CleanSummary (clean_summary )
214
+ return CleanSummary . from_dict (clean_summary )
225
215
elif isinstance (clean_summary , bytes ):
226
- return CleanSummary ({ " clean_time" : clean_summary } )
216
+ return CleanSummary (clean_time = int . from_bytes ( clean_summary , 'big' ) )
227
217
except RoborockTimeout as e :
228
218
_LOGGER .error (e )
229
219
@@ -233,46 +223,46 @@ async def get_clean_record(self, device_id: str, record_id: int) -> CleanRecord:
233
223
device_id , RoborockCommand .GET_CLEAN_RECORD , [record_id ]
234
224
)
235
225
if isinstance (clean_record , dict ):
236
- return CleanRecord (clean_record )
226
+ return CleanRecord . from_dict (clean_record )
237
227
except RoborockTimeout as e :
238
228
_LOGGER .error (e )
239
229
240
230
async def get_consumable (self , device_id : str ) -> Consumable :
241
231
try :
242
232
consumable = await self .send_command (device_id , RoborockCommand .GET_CONSUMABLE )
243
233
if isinstance (consumable , dict ):
244
- return Consumable (consumable )
234
+ return Consumable . from_dict (consumable )
245
235
except RoborockTimeout as e :
246
236
_LOGGER .error (e )
247
237
248
238
async def get_wash_towel_mode (self , device_id : str ) -> WashTowelMode :
249
239
try :
250
240
washing_mode = await self .send_command (device_id , RoborockCommand .GET_WASH_TOWEL_MODE )
251
241
if isinstance (washing_mode , dict ):
252
- return WashTowelMode (washing_mode )
242
+ return WashTowelMode . from_dict (washing_mode )
253
243
except RoborockTimeout as e :
254
244
_LOGGER .error (e )
255
245
256
246
async def get_dust_collection_mode (self , device_id : str ) -> DustCollectionMode :
257
247
try :
258
248
dust_collection = await self .send_command (device_id , RoborockCommand .GET_DUST_COLLECTION_MODE )
259
249
if isinstance (dust_collection , dict ):
260
- return DustCollectionMode (dust_collection )
250
+ return DustCollectionMode . from_dict (dust_collection )
261
251
except RoborockTimeout as e :
262
252
_LOGGER .error (e )
263
253
264
254
async def get_smart_wash_params (self , device_id : str ) -> SmartWashParams :
265
255
try :
266
256
mop_wash_mode = await self .send_command (device_id , RoborockCommand .GET_SMART_WASH_PARAMS )
267
257
if isinstance (mop_wash_mode , dict ):
268
- return SmartWashParams (mop_wash_mode )
258
+ return SmartWashParams . from_dict (mop_wash_mode )
269
259
except RoborockTimeout as e :
270
260
_LOGGER .error (e )
271
261
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 :
273
263
try :
274
264
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 :
276
266
commands += [self .get_wash_towel_mode (device_id ), self .get_smart_wash_params (device_id )]
277
267
[
278
268
dust_collection_mode ,
@@ -302,7 +292,7 @@ async def get_prop(self, device_id: str) -> RoborockDeviceProp | None:
302
292
device_id , clean_summary .records [0 ]
303
293
)
304
294
dock_summary = None
305
- if status and status .dock_type != RoborockDockType .NO_DOCK :
295
+ if status and status .dock_type != RoborockDockTypeCode .NO_DOCK :
306
296
dock_summary = await self .get_dock_summary (device_id , status .dock_type )
307
297
if any ([status , dnd_timer , clean_summary , consumable ]):
308
298
return RoborockDeviceProp (
@@ -316,15 +306,15 @@ async def get_multi_maps_list(self, device_id) -> MultiMapsList:
316
306
device_id , RoborockCommand .GET_MULTI_MAPS_LIST
317
307
)
318
308
if isinstance (multi_maps_list , dict ):
319
- return MultiMapsList (multi_maps_list )
309
+ return MultiMapsList . from_dict (multi_maps_list )
320
310
except RoborockTimeout as e :
321
311
_LOGGER .error (e )
322
312
323
313
async def get_networking (self , device_id ) -> NetworkInfo :
324
314
try :
325
315
networking_info = await self .send_command (device_id , RoborockCommand .GET_NETWORK_INFO )
326
316
if isinstance (networking_info , dict ):
327
- return NetworkInfo (networking_info )
317
+ return NetworkInfo . from_dict (networking_info )
328
318
except RoborockTimeout as e :
329
319
_LOGGER .error (e )
330
320
@@ -390,7 +380,7 @@ async def pass_login(self, password: str) -> UserData:
390
380
391
381
if login_response .get ("code" ) != 200 :
392
382
raise RoborockException (login_response .get ("msg" ))
393
- return UserData (login_response .get ("data" ))
383
+ return UserData . from_dict (login_response .get ("data" ))
394
384
395
385
async def code_login (self , code ) -> UserData :
396
386
base_url = await self ._get_base_url ()
@@ -409,7 +399,7 @@ async def code_login(self, code) -> UserData:
409
399
410
400
if login_response .get ("code" ) != 200 :
411
401
raise RoborockException (login_response .get ("msg" ))
412
- return UserData (login_response .get ("data" ))
402
+ return UserData . from_dict (login_response .get ("data" ))
413
403
414
404
async def get_home_data (self , user_data : UserData ) -> HomeData :
415
405
base_url = await self ._get_base_url ()
@@ -430,8 +420,8 @@ async def get_home_data(self, user_data: UserData) -> HomeData:
430
420
nonce = secrets .token_urlsafe (6 )
431
421
prestr = ":" .join (
432
422
[
433
- rriot .user ,
434
- rriot .password ,
423
+ rriot .u ,
424
+ rriot .s ,
435
425
nonce ,
436
426
str (timestamp ),
437
427
hashlib .md5 (("/user/homes/" + str (home_id )).encode ()).hexdigest (),
@@ -440,17 +430,17 @@ async def get_home_data(self, user_data: UserData) -> HomeData:
440
430
]
441
431
)
442
432
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 ()
444
434
).decode ()
445
435
home_request = PreparedRequest (
446
- rriot .reference . api ,
436
+ rriot .r . a ,
447
437
{
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 } ", '
449
439
f'mac="{ mac } "' ,
450
440
},
451
441
)
452
442
home_response = await home_request .request ("get" , "/user/homes/" + str (home_id ))
453
443
if not home_response .get ("success" ):
454
444
raise RoborockException (home_response )
455
445
home_data = home_response .get ("result" )
456
- return HomeData (home_data )
446
+ return HomeData . from_dict (home_data )
0 commit comments