From f22ad0dfc94166948f5dd915fdf7f4d1b746656d Mon Sep 17 00:00:00 2001 From: Brian Marks Date: Sun, 1 Sep 2024 20:35:08 -0400 Subject: [PATCH] Gracefully handle missing sessionInfo (#40) --- frigidaire/__init__.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/frigidaire/__init__.py b/frigidaire/__init__.py index 46c8bbd..81a112b 100644 --- a/frigidaire/__init__.py +++ b/frigidaire/__init__.py @@ -352,8 +352,13 @@ def authenticate(self) -> None: login_response = self.post_request(f'https://accounts.{identity_domain}', '/accounts.login', self.get_headers_auth("POST"), data, form_encoding=True) - auth_session_token = login_response['sessionInfo']['sessionToken'] - auth_session_secret = login_response['sessionInfo']['sessionSecret'] + session_info = login_response.get('sessionInfo') + if session_info is None or session_info.get('sessionToken') is None or session_info.get('sessionSecret') is None: + raise FrigidaireException( + f'Failed to authenticate, sessionInfo was not in response: {login_response}') + + auth_session_token = session_info['sessionToken'] + auth_session_secret = session_info['sessionSecret'] data = { "apiKey": identity_api_key, @@ -385,12 +390,13 @@ def authenticate(self) -> None: self.get_headers_frigidaire("POST", include_bearer_token=False), data) - if not frigidaire_auth_response.get('accessToken'): + access_token = frigidaire_auth_response.get('accessToken') + if access_token is None: raise FrigidaireException( f'Failed to authenticate, accessToken was not in response: {frigidaire_auth_response}') logging.debug('Authentication successful, storing new session key') - self.session_key = frigidaire_auth_response['accessToken'] + self.session_key = access_token def re_authenticate(self) -> None: """