From 6d1d90757e14a62cedaeda7d0ea11146906db5e9 Mon Sep 17 00:00:00 2001 From: cdnninja Date: Fri, 20 Sep 2024 20:33:23 -0600 Subject: [PATCH] feat: alarm data (#94) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- yoto_api/YotoAPI.py | 27 ++++++++++++++++++++++++++- yoto_api/YotoPlayer.py | 11 +++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/yoto_api/YotoAPI.py b/yoto_api/YotoAPI.py index d7041a9..e7acb32 100644 --- a/yoto_api/YotoAPI.py +++ b/yoto_api/YotoAPI.py @@ -11,9 +11,10 @@ from .Token import Token from .Card import Card, Chapter, Track from .Family import Family -from .YotoPlayer import YotoPlayer, YotoPlayerConfig +from .YotoPlayer import YotoPlayer, YotoPlayerConfig, Alarm from .utils import get_child_value + _LOGGER = logging.getLogger(__name__) @@ -193,6 +194,30 @@ def update_players(self, token: Token, players: list[YotoPlayer]) -> None: players[deviceId].config.night_display_brightness = get_child_value( player_config, "device.config.nightDisplayBrightness" ) + alarms = get_child_value(player_config, "device.config.alarms") + if players[deviceId].config.alarms is None: + players[deviceId].config.alarms = [] + for index in range(len(alarms)): + values = alarms[index].split(",") + if index > len(players[deviceId].config.alarms) - 1: + players[deviceId].config.alarms.append( + Alarm( + days_enabled=values[0], + time=values[1], + sound_id=values[2], + volume=values[5], + enabled=False if len(values) > 6 else True, + ) + ) + else: + players[deviceId].config.alarms[index].days_enabled = values[0] + players[deviceId].config.alarms[index].time = values[1] + players[deviceId].config.alarms[index].sound_id = values[2] + players[deviceId].config.alarms[index].volume = values[5] + players[deviceId].config.alarms[index].enabled = ( + False if len(values) > 6 else True + ) + players[deviceId].last_update_config = datetime.datetime.now(pytz.utc) players[deviceId].last_updated_at = datetime.datetime.now(pytz.utc) diff --git a/yoto_api/YotoPlayer.py b/yoto_api/YotoPlayer.py index a959bfe..7cadef3 100644 --- a/yoto_api/YotoPlayer.py +++ b/yoto_api/YotoPlayer.py @@ -4,6 +4,16 @@ import datetime +@dataclass +class Alarm: + # raw api example. ['0000001,0700,4OD25,,,1,0'] + days_enabled: int = None + enabled: bool = None + time: datetime.time = None + volume: int = None + sound_id: str = None + + @dataclass class YotoPlayerConfig: # Device Config @@ -20,6 +30,7 @@ class YotoPlayerConfig: # Values in HEX_COLORS in const night_ambient_colour: str = None night_max_volume_limit: int = None + alarms: list = None @dataclass