Skip to content

Commit

Permalink
fix: remove dnd timer and valley electricity from props (#75)
Browse files Browse the repository at this point in the history
* fix: remove dnd timer and valley electricity from props

* fix: linting

* fix: clear out old keep alive before adding new one

* chore: remove keep_alive_task

* fix: add storing of dnd and valley in api
  • Loading branch information
Lash-L authored Jun 16, 2023
1 parent 74ced28 commit 2035af5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
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

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

0 comments on commit 2035af5

Please sign in to comment.