Skip to content

Commit

Permalink
feat: alarm data (#94)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
cdnninja and pre-commit-ci[bot] authored Sep 21, 2024
1 parent 9489c34 commit 6d1d907
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
27 changes: 26 additions & 1 deletion yoto_api/YotoAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)


Expand Down Expand Up @@ -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)

Expand Down
11 changes: 11 additions & 0 deletions yoto_api/YotoPlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 6d1d907

Please sign in to comment.