Skip to content

Commit

Permalink
fix: make init non blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
cdnninja committed Apr 15, 2024
1 parent d7c61e3 commit e099c2c
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions yoto_api/YotoManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ def __init__(self, username: str, password: str) -> None:
self.password: str = password
self.api: YotoAPI = YotoAPI()
self.players: dict = {}
self.token: Token = None

self.token: Token = self.api.login(self.username, self.password)
self.token: Token = None
self.players: list = None
self.library: list = None
self.initialize()

def initialize(self) -> None:
self.token: Token = self.api.login(self.username, self.password)
self.update_player_status()
self.update_cards()

Expand All @@ -38,8 +36,9 @@ def update_cards(self) -> None:
def check_and_refresh_token(self) -> bool:
if self.token is None:
self.initialize()
if self.token.valid_until <= dt.datetime.now(pytz.utc):
_LOGGER.debug(f"{DOMAIN} - Refresh token expired")
self.token: Token = self.api.refresh_token(self.token)
return True
return False
# Check if valid and correct if not
#if self.token.valid_until <= dt.datetime.now(pytz.utc):
#_LOGGER.debug(f"{DOMAIN} - Refresh token expired")
#self.token: Token = self.api.refresh_token(self.token)
return True
#return False

0 comments on commit e099c2c

Please sign in to comment.