Skip to content

Commit

Permalink
fix: Alarm Data Index Error (#98)
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 26, 2024
1 parent bb2a34e commit bb0238c
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions yoto_api/YotoAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,23 +200,36 @@ def update_players(self, token: Token, players: list[YotoPlayer]) -> None:
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 values[6] == "0" else True,
# Sometimes the alarm list coming from API is shorter than it should be. This implies new enabled alarm that hasn't been toggled.
if len(values) > 5:
players[deviceId].config.alarms.append(
Alarm(
days_enabled=values[0],
time=values[1],
sound_id=values[2],
volume=values[5],
enabled=False if values[6] == "0" else True,
)
)
else:
players[deviceId].config.alarms.append(
Alarm(
days_enabled=values[0],
time=values[1],
sound_id=values[2],
volume=values[5],
enabled=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 values[6] == "0" else True
)
if len(values) > 5:
players[deviceId].config.alarms[index].enabled = (
False if values[6] == "0" else True
)

players[deviceId].last_update_config = datetime.datetime.now(pytz.utc)
players[deviceId].last_updated_at = datetime.datetime.now(pytz.utc)
Expand Down

0 comments on commit bb0238c

Please sign in to comment.