11"""The Roborock api."""
2+
23from __future__ import annotations
34
45import asyncio
2324import paho .mqtt .client as mqtt
2425from Crypto .Cipher import AES
2526from Crypto .Util .Padding import pad , unpad
26- from roborock .code_mappings import STATE_CODE_TO_STATUS
2727
28- from roborock .containers import (
28+ from roborock .exceptions import (
29+ RoborockException ,
30+ CommandVacuumError ,
31+ VacuumError ,
32+ RoborockTimeout ,
33+ )
34+ from .code_mappings import STATE_CODE_TO_STATUS , WASH_MODE_MAP , DUST_COLLECTION_MAP , RoborockDockType , \
35+ RoborockDockDustCollectionType , RoborockDockWashingModeType
36+ from .containers import (
2937 UserData ,
3038 HomeDataDevice ,
3139 Status ,
3543 CleanRecord ,
3644 HomeData ,
3745 MultiMapsList ,
46+ SmartWashParameters ,
47+
3848)
39- from roborock .exceptions import (
40- RoborockException ,
41- CommandVacuumError ,
42- VacuumError ,
43- RoborockTimeout ,
44- )
45- from roborock .roborock_queue import RoborockQueue
46- from roborock .typing import (
49+ from .roborock_queue import RoborockQueue
50+ from .typing import (
4751 RoborockDeviceInfo ,
4852 RoborockDeviceProp ,
4953 RoborockCommand ,
54+ RoborockDockSummary ,
5055)
51- from roborock .util import run_in_executor
56+ from .util import run_in_executor
5257
5358_LOGGER = logging .getLogger (__name__ )
5459QUEUE_TIMEOUT = 4
@@ -78,17 +83,17 @@ def __init__(self, base_url: str, base_headers: dict = None) -> None:
7883 self .base_headers = base_headers or {}
7984
8085 async def request (
81- self , method : str , url : str , params = None , data = None , headers = None
86+ self , method : str , url : str , params = None , data = None , headers = None
8287 ) -> dict | list :
8388 _url = "/" .join (s .strip ("/" ) for s in [self .base_url , url ])
8489 _headers = {** self .base_headers , ** (headers or {})}
8590 async with aiohttp .ClientSession () as session :
8691 async with session .request (
87- method ,
88- _url ,
89- params = params ,
90- data = data ,
91- headers = _headers ,
92+ method ,
93+ _url ,
94+ params = params ,
95+ data = data ,
96+ headers = _headers ,
9297 ) as resp :
9398 return await resp .json ()
9499
@@ -369,7 +374,7 @@ def _send_msg_raw(self, device_id, protocol, timestamp, payload) -> None:
369374 raise RoborockException (f"Failed to publish (rc: { info .rc } )" )
370375
371376 async def send_command (
372- self , device_id : str , method : RoborockCommand , params : list = None
377+ self , device_id : str , method : RoborockCommand , params : list = None
373378 ):
374379 await self .validate_connection ()
375380 timestamp = math .floor (time .time ())
@@ -439,6 +444,29 @@ async def get_consumable(self, device_id: str) -> Consumable:
439444 if isinstance (consumable , dict ):
440445 return Consumable (consumable )
441446
447+ async def get_washing_mode (self , device_id : str ) -> RoborockDockWashingModeType :
448+ washing_mode = await self .send_command (device_id , RoborockCommand .GET_WASH_TOWEL_MODE )
449+ return WASH_MODE_MAP .get (washing_mode )
450+
451+ async def get_dust_collection_mode (self , device_id : str ) -> RoborockDockDustCollectionType :
452+ dust_collection = await self .send_command (device_id , RoborockCommand .GET_DUST_COLLECTION_MODE )
453+ return DUST_COLLECTION_MAP .get (dust_collection )
454+
455+ async def get_mop_wash_mode (self , device_id : str ) -> SmartWashParameters :
456+ mop_wash_mode = await self .send_command (device_id , RoborockCommand .GET_SMART_WASH_PARAMS )
457+ if isinstance (mop_wash_mode , dict ):
458+ return SmartWashParameters (mop_wash_mode )
459+
460+ async def get_dock_summary (self , device_id : str , dock_type : RoborockDockType ) -> RoborockDockSummary :
461+ collection_mode = await self .get_dust_collection_mode (device_id )
462+ mop_wash = None
463+ washing_mode = None
464+ if dock_type == RoborockDockType .EMPTY_WASH_FILL_DOCK :
465+ [mop_wash , washing_mode ] = await asyncio .gather (
466+ * [self .get_mop_wash_mode (device_id ), self .get_washing_mode (device_id )])
467+
468+ return RoborockDockSummary (collection_mode , washing_mode , mop_wash )
469+
442470 async def get_prop (self , device_id : str ) -> RoborockDeviceProp :
443471 [status , dnd_timer , clean_summary , consumable ] = await asyncio .gather (
444472 * [
@@ -453,9 +481,12 @@ async def get_prop(self, device_id: str) -> RoborockDeviceProp:
453481 last_clean_record = await self .get_clean_record (
454482 device_id , clean_summary .records [0 ]
455483 )
484+ dock_summary = None
485+ if status .dock_type != RoborockDockType .NO_DOCK :
486+ dock_summary = await self .get_dock_summary (device_id , status .dock_type )
456487 if any ([status , dnd_timer , clean_summary , consumable ]):
457488 return RoborockDeviceProp (
458- status , dnd_timer , clean_summary , consumable , last_clean_record
489+ status , dnd_timer , clean_summary , consumable , last_clean_record , dock_summary
459490 )
460491
461492 async def get_multi_maps_list (self , device_id ) -> MultiMapsList :
0 commit comments