Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions roborock/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ def __init__(self, endpoint: str, device_info: DeviceData) -> None:
self._last_disconnection = self.time_func()
self.keep_alive = KEEPALIVE
self._diagnostic_data: dict[str, dict[str, Any]] = {}
self.dnd_timer: DnDTimer | None = None
self.valley_timer: ValleyElectricityTimer | None = None
Comment on lines +106 to +107
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is the best way, but I'm trying to avoid doing the coordinator, and rather than place it in device info, cause then I'd have to make a new function call on top of get_dnd_timer to update it, rather than just setting it here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about something similar. Having an object to hold all executed queries with evicting and caching based on GET / (SET / CHANGE) commands.
You can check them out in roborock_typing CacheableCommands

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that's nice and probably much better long term than this


def __del__(self) -> None:
self.sync_disconnect()
Expand Down Expand Up @@ -255,11 +257,19 @@ async def get_status(self) -> Status | None:

@fallback_cache
async def get_dnd_timer(self) -> DnDTimer | None:
return await self.send_command(RoborockCommand.GET_DND_TIMER, return_type=DnDTimer)
result = await self.send_command(RoborockCommand.GET_DND_TIMER, return_type=DnDTimer)
if result is not None:
self.dnd_timer = result
return result

@fallback_cache
async def get_valley_electricity_timer(self) -> ValleyElectricityTimer | None:
return await self.send_command(RoborockCommand.GET_VALLEY_ELECTRICITY_TIMER, return_type=ValleyElectricityTimer)
result = await self.send_command(
RoborockCommand.GET_VALLEY_ELECTRICITY_TIMER, return_type=ValleyElectricityTimer
)
if result is not None:
self.valley_timer = result
return result

@fallback_cache
async def get_clean_summary(self) -> CleanSummary | None:
Expand Down Expand Up @@ -323,13 +333,11 @@ async def get_dock_summary(self, dock_type: RoborockDockTypeCode) -> DockSummary
@fallback_cache
async def get_prop(self) -> DeviceProp | None:
"""Gets device general properties."""
[status, clean_summary, consumable, dnd_timer, valley_electricity_timer] = await asyncio.gather(
[status, clean_summary, consumable] = await asyncio.gather(
*[
self.get_status(),
self.get_clean_summary(),
self.get_consumable(),
self.get_dnd_timer(),
self.get_valley_electricity_timer(),
]
)
last_clean_record = None
Expand All @@ -338,13 +346,11 @@ async def get_prop(self) -> DeviceProp | None:
dock_summary = None
if status and status.dock_type is not None and status.dock_type != RoborockDockTypeCode.no_dock:
dock_summary = await self.get_dock_summary(status.dock_type)
if any([status, dnd_timer, clean_summary, consumable]):
if any([status, clean_summary, consumable]):
return DeviceProp(
status,
clean_summary,
consumable,
dnd_timer,
valley_electricity_timer,
last_clean_record,
dock_summary,
)
Expand Down
8 changes: 0 additions & 8 deletions roborock/roborock_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
CleanRecord,
CleanSummary,
Consumable,
DnDTimer,
DustCollectionMode,
RoborockBase,
SmartWashParams,
Status,
ValleyElectricityTimer,
WashTowelMode,
)

Expand Down Expand Up @@ -314,8 +312,6 @@ class DeviceProp(RoborockBase):
status: Optional[Status] = None
clean_summary: Optional[CleanSummary] = None
consumable: Optional[Consumable] = None
dnd_timer: Optional[DnDTimer] = None
valley_electricity_timer: Optional[ValleyElectricityTimer] = None
last_clean_record: Optional[CleanRecord] = None
dock_summary: Optional[DockSummary] = None

Expand All @@ -326,10 +322,6 @@ def update(self, device_prop: DeviceProp) -> None:
self.clean_summary = device_prop.clean_summary
if device_prop.consumable:
self.consumable = device_prop.consumable
if device_prop.dnd_timer:
self.dnd_timer = device_prop.dnd_timer
if device_prop.valley_electricity_timer:
self.valley_electricity_timer = device_prop.valley_electricity_timer
if device_prop.last_clean_record:
self.last_clean_record = device_prop.last_clean_record
if device_prop.dock_summary:
Expand Down