Skip to content

Commit

Permalink
Add ability to wait for one facade update
Browse files Browse the repository at this point in the history
Add reminder helper by type
  • Loading branch information
gazoodle committed Mar 16, 2022
1 parent ee9a647 commit 632bac2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/geckolib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
GeckoBinarySensor,
GeckoSwitch,
GeckoWaterCare,
GeckoReminders,
)
from .async_locator import GeckoAsyncLocator
from .async_spa_descriptor import GeckoAsyncSpaDescriptor
Expand All @@ -42,6 +43,7 @@
GeckoWatercareProtocolHandler,
GeckoUpdateFirmwareProtocolHandler,
GeckoRemindersProtocolHandler,
GeckoReminderType,
GeckoPackCommandProtocolHandler,
#
GeckoStructure,
Expand Down Expand Up @@ -79,6 +81,7 @@
"GeckoBinarySensor",
"GeckoSwitch",
"GeckoWaterCare",
"GeckoReminders",
# From constants
"GeckoConstants",
# From facade
Expand Down Expand Up @@ -107,6 +110,7 @@
"GeckoWatercareProtocolHandler",
"GeckoUpdateFirmwareProtocolHandler",
"GeckoRemindersProtocolHandler",
"GeckoReminderType",
"GeckoPackCommandProtocolHandler",
#
"GeckoStructure",
Expand Down
2 changes: 1 addition & 1 deletion src/geckolib/automation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
"GeckoSwitch",
"GeckoWaterCare",
"GeckoReminders",
]
]
8 changes: 8 additions & 0 deletions src/geckolib/automation/async_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __init__(self, spa: GeckoAsyncSpa, taskman: AsyncTasks, **kwargs: str) -> No
device.watch(self._on_change)

self._taskman.add_task(self._facade_update(), "Facade update", "FACADE")
self._ready = False

async def _facade_update(self) -> None:
_LOGGER.debug("Facade update task started")
Expand All @@ -76,6 +77,9 @@ async def _facade_update(self) -> None:
await self._spa.async_get_reminders()
)

# After we've been round here at least once, we're ready
self._ready = True

finally:
wait_time = (
GeckoConstants.FACADE_UPDATE_FREQUENCY_IN_SECONDS
Expand All @@ -88,6 +92,10 @@ async def _facade_update(self) -> None:
_LOGGER.debug("Facade update loop cancelled")
raise

async def wait_for_one_update(self):
while not self._ready:
await asyncio.sleep(0)

def _scan_outputs(self) -> None:
"""Scan the spa outputs to decide what user options are available"""

Expand Down
10 changes: 10 additions & 0 deletions src/geckolib/automation/reminders.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" Gecko Reminders """
from __future__ import annotations

import logging
from datetime import datetime
Expand Down Expand Up @@ -53,6 +54,15 @@ def reminders(self):
"""return all reminders"""
return self._active_reminders

def get_reminder(
self, reminder_type: GeckoReminderType
) -> Optional[GeckoReminders.Reminder]:
"""Get the reminder of the specified type, or None if not found"""
for reminder in self.reminders:
if reminder.type == reminder_type:
return reminder
return None

@property
def last_update(self) -> Optional[datetime]:
"""Time of last reminder update"""
Expand Down
2 changes: 1 addition & 1 deletion src/geckolib/spa_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def to_string(state: GeckoSpaState) -> str:
elif state == GeckoSpaState.ERROR_NEEDS_ATTENTION:
return "Needs attention, check logs"
elif state == GeckoSpaState.LOCATING_SPAS:
return "Searching for spas"
return "Searching for spas..."
elif state == GeckoSpaState.LOCATED_SPAS:
return "Choose spa"
elif state == GeckoSpaState.ERROR_SPA_NOT_FOUND:
Expand Down

0 comments on commit 632bac2

Please sign in to comment.