5151 RoborockCommand .GET_MAP_V1 ,
5252]
5353
54+
5455def md5hex (message : str ) -> str :
5556 md5 = hashlib .md5 ()
5657 md5 .update (message .encode ())
@@ -107,7 +108,7 @@ def _decode_msg(self, msg: bytes, local_key: str) -> dict[str, Any]:
107108 if self ._prefixed :
108109 msg = msg [4 :]
109110 if msg [0 :3 ] != "1.0" .encode ():
110- raise RoborockException ("Unknown protocol version" )
111+ raise RoborockException (f "Unknown protocol version { msg [ 0 : 3 ] } " )
111112 if len (msg ) == 17 :
112113 [version , _seq , _random , timestamp , protocol ] = struct .unpack (
113114 "!3sIIIH" , msg [0 :17 ]
@@ -281,53 +282,75 @@ async def get_status(self, device_id: str) -> Status:
281282 return Status (status )
282283
283284 async def get_dnd_timer (self , device_id : str ) -> DNDTimer :
284- dnd_timer = await self .send_command (device_id , RoborockCommand .GET_DND_TIMER )
285- if isinstance (dnd_timer , dict ):
286- return DNDTimer (dnd_timer )
285+ try :
286+ dnd_timer = await self .send_command (device_id , RoborockCommand .GET_DND_TIMER )
287+ if isinstance (dnd_timer , dict ):
288+ return DNDTimer (dnd_timer )
289+ except RoborockTimeout as e :
290+ _LOGGER .error (e )
287291
288292 async def get_clean_summary (self , device_id : str ) -> CleanSummary :
289- clean_summary = await self .send_command (
290- device_id , RoborockCommand .GET_CLEAN_SUMMARY
291- )
292- if isinstance (clean_summary , dict ):
293- return CleanSummary (clean_summary )
294- elif isinstance (clean_summary , bytes ):
295- return CleanSummary ({"clean_time" : clean_summary })
293+ try :
294+ clean_summary = await self .send_command (
295+ device_id , RoborockCommand .GET_CLEAN_SUMMARY
296+ )
297+ if isinstance (clean_summary , dict ):
298+ return CleanSummary (clean_summary )
299+ elif isinstance (clean_summary , bytes ):
300+ return CleanSummary ({"clean_time" : clean_summary })
301+ except RoborockTimeout as e :
302+ _LOGGER .error (e )
296303
297304 async def get_clean_record (self , device_id : str , record_id : int ) -> CleanRecord :
298- clean_record = await self .send_command (
299- device_id , RoborockCommand .GET_CLEAN_RECORD , [record_id ]
300- )
301- if isinstance (clean_record , dict ):
302- return CleanRecord (clean_record )
305+ try :
306+ clean_record = await self .send_command (
307+ device_id , RoborockCommand .GET_CLEAN_RECORD , [record_id ]
308+ )
309+ if isinstance (clean_record , dict ):
310+ return CleanRecord (clean_record )
311+ except RoborockTimeout as e :
312+ _LOGGER .error (e )
303313
304314 async def get_consumable (self , device_id : str ) -> Consumable :
305- consumable = await self .send_command (device_id , RoborockCommand .GET_CONSUMABLE )
306- if isinstance (consumable , dict ):
307- return Consumable (consumable )
315+ try :
316+ consumable = await self .send_command (device_id , RoborockCommand .GET_CONSUMABLE )
317+ if isinstance (consumable , dict ):
318+ return Consumable (consumable )
319+ except RoborockTimeout as e :
320+ _LOGGER .error (e )
308321
309322 async def get_washing_mode (self , device_id : str ) -> RoborockDockWashingModeType :
310- washing_mode = await self .send_command (device_id , RoborockCommand .GET_WASH_TOWEL_MODE )
311- return WASH_MODE_MAP .get (washing_mode ['wash_mode' ])
323+ try :
324+ washing_mode = await self .send_command (device_id , RoborockCommand .GET_WASH_TOWEL_MODE )
325+ return WASH_MODE_MAP .get (washing_mode ['wash_mode' ])
326+ except RoborockTimeout as e :
327+ _LOGGER .error (e )
312328
313329 async def get_dust_collection_mode (self , device_id : str ) -> RoborockDockDustCollectionType :
314- dust_collection = await self .send_command (device_id , RoborockCommand .GET_DUST_COLLECTION_MODE )
315- return DUST_COLLECTION_MAP .get (dust_collection ['mode' ])
330+ try :
331+ dust_collection = await self .send_command (device_id , RoborockCommand .GET_DUST_COLLECTION_MODE )
332+ return DUST_COLLECTION_MAP .get (dust_collection ['mode' ])
333+ except RoborockTimeout as e :
334+ _LOGGER .error (e )
316335
317336 async def get_mop_wash_mode (self , device_id : str ) -> SmartWashParameters :
318- mop_wash_mode = await self .send_command (device_id , RoborockCommand .GET_SMART_WASH_PARAMS )
319- if isinstance (mop_wash_mode , dict ):
320- return SmartWashParameters (mop_wash_mode )
337+ try :
338+ mop_wash_mode = await self .send_command (device_id , RoborockCommand .GET_SMART_WASH_PARAMS )
339+ if isinstance (mop_wash_mode , dict ):
340+ return SmartWashParameters (mop_wash_mode )
341+ except RoborockTimeout as e :
342+ _LOGGER .error (e )
321343
322344 async def get_dock_summary (self , device_id : str , dock_type : RoborockDockType ) -> RoborockDockSummary :
323- collection_mode = await self .get_dust_collection_mode (device_id )
324- mop_wash = None
325- washing_mode = None
326- if dock_type == RoborockDockType .EMPTY_WASH_FILL_DOCK :
327- [mop_wash , washing_mode ] = await asyncio .gather (
328- * [self .get_mop_wash_mode (device_id ), self .get_washing_mode (device_id )])
345+ try :
346+ commands = [self .get_dust_collection_mode (device_id )]
347+ if dock_type == RoborockDockType .EMPTY_WASH_FILL_DOCK :
348+ commands += [self .get_mop_wash_mode (device_id ), self .get_washing_mode (device_id )]
349+ [collection_mode , mop_wash , washing_mode ] = (list (await asyncio .gather (* commands )) + [None , None ])[:3 ]
329350
330- return RoborockDockSummary (collection_mode , washing_mode , mop_wash )
351+ return RoborockDockSummary (collection_mode , washing_mode , mop_wash )
352+ except RoborockTimeout as e :
353+ _LOGGER .error (e )
331354
332355 async def get_prop (self , device_id : str ) -> RoborockDeviceProp :
333356 [status , dnd_timer , clean_summary , consumable ] = await asyncio .gather (
@@ -338,17 +361,9 @@ async def get_prop(self, device_id: str) -> RoborockDeviceProp:
338361 self .get_consumable (device_id ),
339362 ]
340363 )
341- last_clean_record = None
342- # if clean_summary and clean_summary.records and len(clean_summary.records) > 0:
343- # last_clean_record = await self.get_clean_record(
344- # device_id, clean_summary.records[0]
345- # )
346- dock_summary = None
347- if status and status .dock_type != RoborockDockType .NO_DOCK :
348- dock_summary = await self .get_dock_summary (device_id , status .dock_type )
349364 if any ([status , dnd_timer , clean_summary , consumable ]):
350365 return RoborockDeviceProp (
351- status , dnd_timer , clean_summary , consumable , last_clean_record , dock_summary
366+ status , dnd_timer , clean_summary , consumable
352367 )
353368
354369 async def get_multi_maps_list (self , device_id ) -> MultiMapsList :
0 commit comments