Skip to content

Commit

Permalink
Update api_renpho.py
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinebou12 authored Mar 2, 2024
1 parent 836f872 commit 63ae960
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions custom_components/renpho/api_renpho.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(self, public_key, email, password, user_id=None, refresh=60):
self.refresh = refresh
self.session = None
self.is_polling_active = False
self.session_key_expiry = datetime.utcnow() - timedelta(minutes=1)
self.session_key_expiry = datetime.datetime.utcnow() - timedelta(minutes=1)

def set_user_id(self, user_id):
"""
Expand Down Expand Up @@ -93,8 +93,6 @@ def prepare_data(self, data):

async def open_session(self):
if self.session is None or self.session.closed:
self.session_key = None
self.session_key_expiry = datetime.datetime.now()
self.session = aiohttp.ClientSession()

async def _request(self, method: str, url: str, retries=3, backoff_factor=0.5, **kwargs) -> Union[Dict, List]:
Expand Down Expand Up @@ -203,7 +201,7 @@ async def auth(self):

# If everything is fine, set the session_key
self.session_key = parsed["terminal_user_session_key"]
self.session_key_expiry = datetime.datetime.now() + datetime.timedelta(minutes=10)
self.session_key_expiry = datetime.datetime.utcnow() + datetime.timedelta(minutes=10)
return parsed

async def ensure_valid_session(self):
Expand All @@ -214,7 +212,7 @@ async def ensure_valid_session(self):

def is_session_valid(self):
"""Check if the session key is valid."""
return self.session_key and datetime.utcnow() < self.session_key_expiry
return self.session_key and datetime.datetime.utcnow() < self.session_key_expiry

async def validate_credentials(self):
"""
Expand Down

0 comments on commit 63ae960

Please sign in to comment.