Skip to content

Commit

Permalink
feat: Additional Data Points
Browse files Browse the repository at this point in the history
  • Loading branch information
cdnninja committed Apr 23, 2024
1 parent f2ff9e0 commit 09380be
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
14 changes: 10 additions & 4 deletions yoto_api/YotoAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from datetime import timedelta
import pytz
from .const import DOMAIN
from .const import DOMAIN, LIGHT_COLORS, POWER_SOURCE
from .Token import Token
from .Card import Card
from .YotoPlayer import YotoPlayer
Expand Down Expand Up @@ -82,9 +82,12 @@ def update_players(self, token: Token, players: list[YotoPlayer]) -> None:
players[deviceId].name = self.get_child_value(item, "name")
players[deviceId].device_type = self.get_child_value(item, "deviceType")
players[deviceId].online = self.get_child_value(item, "online")
players[deviceId].last_updated_at = datetime.datetime.now(pytz.utc)

# Should we call here or make this a separate call from YM? This could help us reduce API calls.
player_status_response = self._get_device_status(token, deviceId)
players[deviceId].last_updated_at = self.get_child_value(
player_status_response, "updatedAt"
)
if self.get_child_value(
player_status_response, "activeCard"
) is not "none":
Expand Down Expand Up @@ -130,9 +133,12 @@ def update_players(self, token: Token, players: list[YotoPlayer]) -> None:
players[deviceId].playing_source = self.get_child_value(
player_status_response, "playingSource"
)
players[deviceId].night_light_mode = self.get_child_value(
players[deviceId].night_light_mode = LIGHT_COLORS[self.get_child_value(
player_status_response, "nightlightMode"
)
)]
players[deviceId].plugged_in = POWER_SOURCE[self.get_child_value(
player_status_response, "powerSource"
)]

def update_library(self, token: Token, library: dict[Card]) -> list[Card]:
response = self._get_cards(token)
Expand Down
2 changes: 2 additions & 0 deletions yoto_api/YotoPlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class YotoPlayer:
ambient_light_sensor_reading: int = None
battery_level_percentage: int = None
night_mode_on: bool = None
night_light_mode: str = None
user_volume: int = None
system_volume: int = None
temperature_celcius: int = None
Expand All @@ -28,6 +29,7 @@ class YotoPlayer:
audio_device_connected: bool = None
firmware_version: str = None
wifi_strength: int = None
plugged_in: bool = None


# {'devices': [{'deviceId': 'XXXX', 'name': 'Yoto Player', 'description': 'nameless.limit', 'online': False, 'releaseChannel': 'general', 'deviceType': 'v3', 'deviceFamily': 'v3', 'deviceGroup': '', 'hasUserGivenName': False}]}
Expand Down
15 changes: 15 additions & 0 deletions yoto_api/const.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
"""const.py"""

DOMAIN: str = "yoto_api"

# Blue night_light_mode 0x194a55
# off is 0x000000

LIGHT_COLORS = {
None: None,
"0x000000": "Off",
"0x194a55": "On"
}

POWER_SOURCE = {
# Guessing on this.
1: False,
2: True
}

0 comments on commit 09380be

Please sign in to comment.