-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Active & Idle configuration settings added
Facade controls which config mode to use
- Loading branch information
Showing
9 changed files
with
146 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,88 @@ | ||
"""Configuration management for geckolib""" | ||
|
||
import asyncio | ||
from dataclasses import dataclass | ||
import logging | ||
from typing import Optional | ||
|
||
class _GeckoConfigManager: | ||
"""Configuration manangement class""" | ||
_LOGGER = logging.getLogger(__name__) | ||
|
||
@property | ||
def DISCOVERY_INITIAL_TIMEOUT_IN_SECONDS(self): | ||
"""Mininum time in seconds to wait for initial spa discovery even | ||
if one spa has responded""" | ||
return 4 | ||
|
||
@property | ||
def DISCOVERY_TIMEOUT_IN_SECONDS(self): | ||
"""Maximum time in seconds to wait for full discovery if no spas | ||
have responded""" | ||
return 10 | ||
@dataclass | ||
class _GeckoConfig: | ||
DISCOVERY_INITIAL_TIMEOUT_IN_SECONDS = 1 | ||
"""Mininum time in seconds to wait for initial spa discovery even | ||
if one spa has responded""" | ||
|
||
@property | ||
def TASK_TIDY_FREQUENCY_IN_SECONDS(self): | ||
"""Time in seconds between task tidyup checks""" | ||
return 5 | ||
DISCOVERY_TIMEOUT_IN_SECONDS = 1 | ||
"""Maximum time in seconds to wait for full discovery if no spas | ||
have responded""" | ||
|
||
@property | ||
def PING_FREQUENCY_IN_SECONDS(self): | ||
"""Frequency in seconds to ping the spa to ensure it is still available""" | ||
return 10 | ||
TASK_TIDY_FREQUENCY_IN_SECONDS = 1 | ||
"""Time in seconds between task tidyup checks""" | ||
|
||
@property | ||
def PING_DEVICE_NOT_RESPONDING_TIMEOUT_IN_SECONDS(self): | ||
"""Time after which a spa is deemed to be not responding to pings""" | ||
return 10 | ||
PING_FREQUENCY_IN_SECONDS = 1 | ||
"""Frequency in seconds to ping the spa to ensure it is still available""" | ||
|
||
@property | ||
def FACADE_UPDATE_FREQUENCY_IN_SECONDS(self): | ||
"""Frequency in seconds to update facade data""" | ||
return 30 | ||
PING_DEVICE_NOT_RESPONDING_TIMEOUT_IN_SECONDS = 1 | ||
"""Time after which a spa is deemed to be not responding to pings""" | ||
|
||
@property | ||
def SPA_PACK_REFRESH_FREQUENCY_IN_SECONDS(self): | ||
"""Frequency in seconds to request all LOG data from spa""" | ||
return 30 | ||
FACADE_UPDATE_FREQUENCY_IN_SECONDS = 1 | ||
"""Frequency in seconds to update facade data""" | ||
|
||
SPA_PACK_REFRESH_FREQUENCY_IN_SECONDS = 1 | ||
"""Frequency in seconds to request all LOG data from spa""" | ||
|
||
|
||
CONFIG_MEMBERS = [ | ||
attr | ||
for attr in dir(_GeckoConfig) | ||
if not callable(getattr(_GeckoConfig, attr)) and not attr.startswith("__") | ||
] | ||
|
||
|
||
@dataclass | ||
class _GeckoActiveConfig(_GeckoConfig): | ||
"""Gecko active configuration""" | ||
|
||
DISCOVERY_INITIAL_TIMEOUT_IN_SECONDS = 4 | ||
DISCOVERY_TIMEOUT_IN_SECONDS = 10 | ||
TASK_TIDY_FREQUENCY_IN_SECONDS = 5 | ||
PING_FREQUENCY_IN_SECONDS = 2 | ||
PING_DEVICE_NOT_RESPONDING_TIMEOUT_IN_SECONDS = 10 | ||
FACADE_UPDATE_FREQUENCY_IN_SECONDS = 30 | ||
SPA_PACK_REFRESH_FREQUENCY_IN_SECONDS = 30 | ||
|
||
|
||
@dataclass | ||
class _GeckoIdleConfig(_GeckoConfig): | ||
"""Gecko idle configuration""" | ||
|
||
DISCOVERY_INITIAL_TIMEOUT_IN_SECONDS = 4 | ||
DISCOVERY_TIMEOUT_IN_SECONDS = 10 | ||
TASK_TIDY_FREQUENCY_IN_SECONDS = 60 | ||
PING_FREQUENCY_IN_SECONDS = 60 | ||
PING_DEVICE_NOT_RESPONDING_TIMEOUT_IN_SECONDS = 120 | ||
FACADE_UPDATE_FREQUENCY_IN_SECONDS = 120 | ||
SPA_PACK_REFRESH_FREQUENCY_IN_SECONDS = 120 | ||
|
||
|
||
# Root config | ||
GeckoConfig = _GeckoConfigManager() | ||
GeckoConfig: _GeckoConfig = _GeckoIdleConfig() | ||
ConfigChange: Optional[asyncio.Future] = None | ||
|
||
|
||
def set_config_mode(active: bool) -> None: | ||
"""Set config mode to active (true) or idle (false).""" | ||
new_config = _GeckoActiveConfig() if active else _GeckoIdleConfig() | ||
for member in CONFIG_MEMBERS: | ||
setattr(GeckoConfig, member, getattr(new_config, member)) | ||
assert ConfigChange is not None | ||
ConfigChange.set_result(True) | ||
|
||
|
||
async def config_sleep(delay: float) -> None: | ||
global ConfigChange | ||
if ConfigChange is None or ConfigChange.done(): | ||
ConfigChange = asyncio.get_running_loop().create_future() | ||
await asyncio.wait([ConfigChange], timeout=delay) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters