Skip to content

Commit

Permalink
fix: memory issue with updates
Browse files Browse the repository at this point in the history
  • Loading branch information
cdnninja committed Apr 19, 2024
1 parent 1ccae9a commit 1cc9fda
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytz
requests
2 changes: 2 additions & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytz
requests
25 changes: 11 additions & 14 deletions yoto_api/YotoAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion yoto_api/YotoManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 1cc9fda

Please sign in to comment.