diff --git a/requirements.txt b/requirements.txt index e69de29..b9d6fbf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -0,0 +1,2 @@ +pytz +requests \ No newline at end of file diff --git a/requirements_dev.txt b/requirements_dev.txt index e69de29..b9d6fbf 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -0,0 +1,2 @@ +pytz +requests \ No newline at end of file diff --git a/yoto_api/YotoAPI.py b/yoto_api/YotoAPI.py index a23d28b..51714c9 100644 --- a/yoto_api/YotoAPI.py +++ b/yoto_api/YotoAPI.py @@ -50,21 +50,18 @@ def login(self, username: str, password: str) -> Token: # pass='audience=https%3A//api.yotoplay.com&client_id=FILL_THIS_IN&grant_type=password&password=FILL_THIS_IN&scope=openid%20email%20profile%20offline_access&username=FILL_THIS_IN%40gmail.com' # curl -d "$pass" https://api.yotoplay.com/auth/token | jq '.access_token' - def update_devices(self, token) -> dict[YotoPlayer]: - response = self._get_devices(token) - result = {} - for device in response["devices"]: - player: YotoPlayer = YotoPlayer( - id=device["deviceId"], - name=device["name"], - deviceType=device["deviceType"], - online=device["online"], - last_updated_at=datetime.datetime.now(pytz.utc) - ) - result[player.id] = player + def update_devices(self, token, devices) -> dict[YotoPlayer]: + response = self._get_devices(token) + if devices is None: + devices = {} + else: + for player in response["devices"]: + devices[player.id].id = player["deviceId"] + devices[player.id].name = player["name"] + devices[player.id].deviceType = player["deviceType"] + devices[player.id].last_update_at = datetime.datetime.now(pytz.utc) + devices[player.id].online = player["online"], - return result - # TODO: parse the data and return a list of yoto devices. def update_library(self, token) -> list[Card]: cards = self._get_cards(token) diff --git a/yoto_api/YotoManager.py b/yoto_api/YotoManager.py index 068abe8..a6a6573 100644 --- a/yoto_api/YotoManager.py +++ b/yoto_api/YotoManager.py @@ -27,7 +27,7 @@ def initialize(self) -> None: def update_player_status(self) -> None: # Updates the data with current player data. - self.players = self.api.update_devices(self.token) + self.players = self.api.update_devices(self.token, self.players) def update_cards(self) -> None: # Updates library and all card data. Typically only required on startup.