Skip to content

Commit 12d7c0b

Browse files
fix: pycharm typing
1 parent bfaf249 commit 12d7c0b

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

roborock/api.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def _get_payload(
225225
async def send_command(self, method: RoborockCommand, params: Optional[list | dict] = None):
226226
raise NotImplementedError
227227

228-
@fallback_cache()
228+
@fallback_cache
229229
async def get_status(self) -> Status | None:
230230
status = await self.send_command(RoborockCommand.GET_STATUS)
231231
if isinstance(status, dict):
@@ -235,14 +235,14 @@ async def get_status(self) -> Status | None:
235235
return _cls.from_dict(status)
236236
return None
237237

238-
@fallback_cache()
238+
@fallback_cache
239239
async def get_dnd_timer(self) -> DnDTimer | None:
240240
dnd_timer = await self.send_command(RoborockCommand.GET_DND_TIMER)
241241
if isinstance(dnd_timer, dict):
242242
return DnDTimer.from_dict(dnd_timer)
243243
return None
244244

245-
@fallback_cache()
245+
@fallback_cache
246246
async def get_clean_summary(self) -> CleanSummary | None:
247247
clean_summary = await self.send_command(RoborockCommand.GET_CLEAN_SUMMARY)
248248
if isinstance(clean_summary, dict):
@@ -259,42 +259,42 @@ async def get_clean_summary(self) -> CleanSummary | None:
259259
return CleanSummary(clean_time=clean_summary)
260260
return None
261261

262-
@fallback_cache()
262+
@fallback_cache
263263
async def get_clean_record(self, record_id: int) -> CleanRecord | None:
264264
clean_record = await self.send_command(RoborockCommand.GET_CLEAN_RECORD, [record_id])
265265
if isinstance(clean_record, dict):
266266
return CleanRecord.from_dict(clean_record)
267267
return None
268268

269-
@fallback_cache()
269+
@fallback_cache
270270
async def get_consumable(self) -> Consumable | None:
271271
consumable = await self.send_command(RoborockCommand.GET_CONSUMABLE)
272272
if isinstance(consumable, dict):
273273
return Consumable.from_dict(consumable)
274274
return None
275275

276-
@fallback_cache()
276+
@fallback_cache
277277
async def get_wash_towel_mode(self) -> WashTowelMode | None:
278278
washing_mode = await self.send_command(RoborockCommand.GET_WASH_TOWEL_MODE)
279279
if isinstance(washing_mode, dict):
280280
return WashTowelMode.from_dict(washing_mode)
281281
return None
282282

283-
@fallback_cache()
283+
@fallback_cache
284284
async def get_dust_collection_mode(self) -> DustCollectionMode | None:
285285
dust_collection = await self.send_command(RoborockCommand.GET_DUST_COLLECTION_MODE)
286286
if isinstance(dust_collection, dict):
287287
return DustCollectionMode.from_dict(dust_collection)
288288
return None
289289

290-
@fallback_cache()
290+
@fallback_cache
291291
async def get_smart_wash_params(self) -> SmartWashParams | None:
292292
mop_wash_mode = await self.send_command(RoborockCommand.GET_SMART_WASH_PARAMS)
293293
if isinstance(mop_wash_mode, dict):
294294
return SmartWashParams.from_dict(mop_wash_mode)
295295
return None
296296

297-
@fallback_cache()
297+
@fallback_cache
298298
async def get_dock_summary(self, dock_type: RoborockDockTypeCode) -> DockSummary | None:
299299
"""Gets the status summary from the dock with the methods available for a given dock.
300300
@@ -316,7 +316,7 @@ async def get_dock_summary(self, dock_type: RoborockDockTypeCode) -> DockSummary
316316
)
317317
return DockSummary(dust_collection_mode, wash_towel_mode, smart_wash_params)
318318

319-
@fallback_cache()
319+
@fallback_cache
320320
async def get_prop(self) -> DeviceProp | None:
321321
"""Gets device general properties."""
322322
[status, dnd_timer, clean_summary, consumable] = await asyncio.gather(
@@ -344,21 +344,21 @@ async def get_prop(self) -> DeviceProp | None:
344344
)
345345
return None
346346

347-
@fallback_cache()
347+
@fallback_cache
348348
async def get_multi_maps_list(self) -> MultiMapsList | None:
349349
multi_maps_list = await self.send_command(RoborockCommand.GET_MULTI_MAPS_LIST)
350350
if isinstance(multi_maps_list, dict):
351351
return MultiMapsList.from_dict(multi_maps_list)
352352
return None
353353

354-
@fallback_cache()
354+
@fallback_cache
355355
async def get_networking(self) -> NetworkInfo | None:
356356
networking_info = await self.send_command(RoborockCommand.GET_NETWORK_INFO)
357357
if isinstance(networking_info, dict):
358358
return NetworkInfo.from_dict(networking_info)
359359
return None
360360

361-
@fallback_cache()
361+
@fallback_cache
362362
async def get_room_mapping(self) -> list[RoomMapping] | None:
363363
"""Gets the mapping from segment id -> iot id. Only works on local api."""
364364
mapping = await self.send_command(RoborockCommand.GET_ROOM_MAPPING)

roborock/util.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import asyncio
44
import functools
55
from asyncio import AbstractEventLoop
6-
from typing import Any, Awaitable, Callable, Optional, TypeVar
6+
from typing import Callable, Coroutine, Optional, TypeVar
77

88
T = TypeVar("T")
99

@@ -38,19 +38,19 @@ class CacheableResult:
3838
last_run_result = None
3939

4040

41-
def fallback_cache():
42-
cache = CacheableResult()
41+
RT = TypeVar("RT", bound=Callable[..., Coroutine])
4342

44-
def decorator(func: Callable[[Any, Any], Awaitable[Any]]):
45-
@functools.wraps(func)
46-
async def wrapped(*args, **kwargs):
47-
try:
48-
cache.last_run_result = await func(*args, **kwargs)
49-
except Exception as e:
50-
if cache.last_run_result is None:
51-
raise e
52-
return cache.last_run_result
5343

54-
return wrapped
44+
def fallback_cache(func: RT) -> RT:
45+
cache = CacheableResult()
5546

56-
return decorator
47+
@functools.wraps(func)
48+
async def wrapped(*args, **kwargs):
49+
try:
50+
cache.last_run_result = await func(*args, **kwargs)
51+
except Exception as e:
52+
if cache.last_run_result is None:
53+
raise e
54+
return cache.last_run_result
55+
56+
return wrapped # type: ignore

0 commit comments

Comments
 (0)