14
14
import struct
15
15
import time
16
16
from random import randint
17
- from typing import Any , Callable , Coroutine , Mapping , Optional
17
+ from typing import Any , Callable , Coroutine , Optional
18
18
19
19
import aiohttp
20
20
from Crypto .Cipher import AES
@@ -85,8 +85,8 @@ async def request(self, method: str, url: str, params=None, data=None, headers=N
85
85
86
86
87
87
class RoborockClient :
88
- def __init__ (self , endpoint : str , devices_info : Mapping [ str , RoborockDeviceInfo ] ) -> None :
89
- self .devices_info = devices_info
88
+ def __init__ (self , endpoint : str , device_info : RoborockDeviceInfo ) -> None :
89
+ self .device_info = device_info
90
90
self ._endpoint = endpoint
91
91
self ._nonce = secrets .token_bytes (16 )
92
92
self ._waiting_queue : dict [int , RoborockFuture ] = {}
@@ -200,27 +200,27 @@ def _get_payload(self, method: RoborockCommand, params: Optional[list] = None, s
200
200
)
201
201
return request_id , timestamp , payload
202
202
203
- async def send_command (self , device_id : str , method : RoborockCommand , params : Optional [list ] = None ):
203
+ async def send_command (self , method : RoborockCommand , params : Optional [list ] = None ):
204
204
raise NotImplementedError
205
205
206
- async def get_status (self , device_id : str ) -> Status | None :
207
- status = await self .send_command (device_id , RoborockCommand .GET_STATUS )
206
+ async def get_status (self ) -> Status | None :
207
+ status = await self .send_command (RoborockCommand .GET_STATUS )
208
208
if isinstance (status , dict ):
209
209
return Status .from_dict (status )
210
210
return None
211
211
212
- async def get_dnd_timer (self , device_id : str ) -> DNDTimer | None :
212
+ async def get_dnd_timer (self ) -> DNDTimer | None :
213
213
try :
214
- dnd_timer = await self .send_command (device_id , RoborockCommand .GET_DND_TIMER )
214
+ dnd_timer = await self .send_command (RoborockCommand .GET_DND_TIMER )
215
215
if isinstance (dnd_timer , dict ):
216
216
return DNDTimer .from_dict (dnd_timer )
217
217
except RoborockTimeout as e :
218
218
_LOGGER .error (e )
219
219
return None
220
220
221
- async def get_clean_summary (self , device_id : str ) -> CleanSummary | None :
221
+ async def get_clean_summary (self ) -> CleanSummary | None :
222
222
try :
223
- clean_summary = await self .send_command (device_id , RoborockCommand .GET_CLEAN_SUMMARY )
223
+ clean_summary = await self .send_command (RoborockCommand .GET_CLEAN_SUMMARY )
224
224
if isinstance (clean_summary , dict ):
225
225
return CleanSummary .from_dict (clean_summary )
226
226
elif isinstance (clean_summary , list ):
@@ -232,55 +232,54 @@ async def get_clean_summary(self, device_id: str) -> CleanSummary | None:
232
232
_LOGGER .error (e )
233
233
return None
234
234
235
- async def get_clean_record (self , device_id : str , record_id : int ) -> CleanRecord | None :
235
+ async def get_clean_record (self , record_id : int ) -> CleanRecord | None :
236
236
try :
237
- clean_record = await self .send_command (device_id , RoborockCommand .GET_CLEAN_RECORD , [record_id ])
237
+ clean_record = await self .send_command (RoborockCommand .GET_CLEAN_RECORD , [record_id ])
238
238
if isinstance (clean_record , dict ):
239
239
return CleanRecord .from_dict (clean_record )
240
240
except RoborockTimeout as e :
241
241
_LOGGER .error (e )
242
242
return None
243
243
244
- async def get_consumable (self , device_id : str ) -> Consumable | None :
244
+ async def get_consumable (self ) -> Consumable | None :
245
245
try :
246
- consumable = await self .send_command (device_id , RoborockCommand .GET_CONSUMABLE )
246
+ consumable = await self .send_command (RoborockCommand .GET_CONSUMABLE )
247
247
if isinstance (consumable , dict ):
248
248
return Consumable .from_dict (consumable )
249
249
except RoborockTimeout as e :
250
250
_LOGGER .error (e )
251
251
return None
252
252
253
- async def get_wash_towel_mode (self , device_id : str ) -> WashTowelMode | None :
253
+ async def get_wash_towel_mode (self ) -> WashTowelMode | None :
254
254
try :
255
- washing_mode = await self .send_command (device_id , RoborockCommand .GET_WASH_TOWEL_MODE )
255
+ washing_mode = await self .send_command (RoborockCommand .GET_WASH_TOWEL_MODE )
256
256
if isinstance (washing_mode , dict ):
257
257
return WashTowelMode .from_dict (washing_mode )
258
258
except RoborockTimeout as e :
259
259
_LOGGER .error (e )
260
260
return None
261
261
262
- async def get_dust_collection_mode (self , device_id : str ) -> DustCollectionMode | None :
262
+ async def get_dust_collection_mode (self ) -> DustCollectionMode | None :
263
263
try :
264
- dust_collection = await self .send_command (device_id , RoborockCommand .GET_DUST_COLLECTION_MODE )
264
+ dust_collection = await self .send_command (RoborockCommand .GET_DUST_COLLECTION_MODE )
265
265
if isinstance (dust_collection , dict ):
266
266
return DustCollectionMode .from_dict (dust_collection )
267
267
except RoborockTimeout as e :
268
268
_LOGGER .error (e )
269
269
return None
270
270
271
- async def get_smart_wash_params (self , device_id : str ) -> SmartWashParams | None :
271
+ async def get_smart_wash_params (self ) -> SmartWashParams | None :
272
272
try :
273
- mop_wash_mode = await self .send_command (device_id , RoborockCommand .GET_SMART_WASH_PARAMS )
273
+ mop_wash_mode = await self .send_command (RoborockCommand .GET_SMART_WASH_PARAMS )
274
274
if isinstance (mop_wash_mode , dict ):
275
275
return SmartWashParams .from_dict (mop_wash_mode )
276
276
except RoborockTimeout as e :
277
277
_LOGGER .error (e )
278
278
return None
279
279
280
- async def get_dock_summary (self , device_id : str , dock_type : RoborockEnum ) -> DockSummary | None :
280
+ async def get_dock_summary (self , dock_type : RoborockEnum ) -> DockSummary | None :
281
281
"""Gets the status summary from the dock with the methods available for a given dock.
282
282
283
- :param device_id: Device id
284
283
:param dock_type: RoborockDockTypeCode"""
285
284
try :
286
285
commands : list [
@@ -289,11 +288,11 @@ async def get_dock_summary(self, device_id: str, dock_type: RoborockEnum) -> Doc
289
288
Any ,
290
289
DustCollectionMode | WashTowelMode | SmartWashParams | None ,
291
290
]
292
- ] = [self .get_dust_collection_mode (device_id )]
291
+ ] = [self .get_dust_collection_mode ()]
293
292
if dock_type == RoborockDockTypeCode ["3" ]:
294
293
commands += [
295
- self .get_wash_towel_mode (device_id ),
296
- self .get_smart_wash_params (device_id ),
294
+ self .get_wash_towel_mode (),
295
+ self .get_smart_wash_params (),
297
296
]
298
297
[dust_collection_mode , wash_towel_mode , smart_wash_params ] = unpack_list (
299
298
list (await asyncio .gather (* commands )), 3
@@ -304,21 +303,21 @@ async def get_dock_summary(self, device_id: str, dock_type: RoborockEnum) -> Doc
304
303
_LOGGER .error (e )
305
304
return None
306
305
307
- async def get_prop (self , device_id : str ) -> DeviceProp | None :
306
+ async def get_prop (self ) -> DeviceProp | None :
308
307
[status , dnd_timer , clean_summary , consumable ] = await asyncio .gather (
309
308
* [
310
- self .get_status (device_id ),
311
- self .get_dnd_timer (device_id ),
312
- self .get_clean_summary (device_id ),
313
- self .get_consumable (device_id ),
309
+ self .get_status (),
310
+ self .get_dnd_timer (),
311
+ self .get_clean_summary (),
312
+ self .get_consumable (),
314
313
]
315
314
)
316
315
last_clean_record = None
317
316
if clean_summary and clean_summary .records and len (clean_summary .records ) > 0 :
318
- last_clean_record = await self .get_clean_record (device_id , clean_summary .records [0 ])
317
+ last_clean_record = await self .get_clean_record (clean_summary .records [0 ])
319
318
dock_summary = None
320
319
if status and status .dock_type is not None and status .dock_type != RoborockDockTypeCode ["0" ]:
321
- dock_summary = await self .get_dock_summary (device_id , status .dock_type )
320
+ dock_summary = await self .get_dock_summary (status .dock_type )
322
321
if any ([status , dnd_timer , clean_summary , consumable ]):
323
322
return DeviceProp (
324
323
status ,
@@ -330,27 +329,27 @@ async def get_prop(self, device_id: str) -> DeviceProp | None:
330
329
)
331
330
return None
332
331
333
- async def get_multi_maps_list (self , device_id ) -> MultiMapsList | None :
332
+ async def get_multi_maps_list (self ) -> MultiMapsList | None :
334
333
try :
335
- multi_maps_list = await self .send_command (device_id , RoborockCommand .GET_MULTI_MAPS_LIST )
334
+ multi_maps_list = await self .send_command (RoborockCommand .GET_MULTI_MAPS_LIST )
336
335
if isinstance (multi_maps_list , dict ):
337
336
return MultiMapsList .from_dict (multi_maps_list )
338
337
except RoborockTimeout as e :
339
338
_LOGGER .error (e )
340
339
return None
341
340
342
- async def get_networking (self , device_id ) -> NetworkInfo | None :
341
+ async def get_networking (self ) -> NetworkInfo | None :
343
342
try :
344
- networking_info = await self .send_command (device_id , RoborockCommand .GET_NETWORK_INFO )
343
+ networking_info = await self .send_command (RoborockCommand .GET_NETWORK_INFO )
345
344
if isinstance (networking_info , dict ):
346
345
return NetworkInfo .from_dict (networking_info )
347
346
except RoborockTimeout as e :
348
347
_LOGGER .error (e )
349
348
return None
350
349
351
- async def get_room_mapping (self , device_id : str ) -> list [RoomMapping ]:
350
+ async def get_room_mapping (self ) -> list [RoomMapping ]:
352
351
"""Gets the mapping from segment id -> iot id. Only works on local api."""
353
- mapping = await self .send_command (device_id , RoborockCommand .GET_ROOM_MAPPING )
352
+ mapping = await self .send_command (RoborockCommand .GET_ROOM_MAPPING )
354
353
if isinstance (mapping , list ):
355
354
return [
356
355
RoomMapping (segment_id = segment_id , iot_id = iot_id ) # type: ignore
0 commit comments