Skip to content

Commit

Permalink
Fixed None Type Sensor errors; Allow patient account (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
sedy89 authored Jan 9, 2024
1 parent 73494fd commit eae2c9e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
3 changes: 2 additions & 1 deletion custom_components/carelink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ async def _async_update_data(self):

await self.client.login()
recent_data = await self.client.get_recent_data()

if recent_data is None:
recent_data = dict()
try:
if recent_data is not None and "clientTimeZoneName" in recent_data:
client_timezone = recent_data["clientTimeZoneName"]
Expand Down
26 changes: 12 additions & 14 deletions custom_components/carelink/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,11 @@ async def __get_data(self, host, path, query_params, request_body):

def __selectPatient(self, patients):
patient = None
for p in patients:
if p["status"] == "ACTIVE":
patient = p
break
if patients is not None:
for p in patients:
if p["status"] == "ACTIVE":
patient = p
break
return patient

async def __getPatients(self):
Expand Down Expand Up @@ -307,7 +308,7 @@ async def __execute_login_procedure(self):
self.__carelink_patient_id = patient["username"]
printdbg("Found patient %s %s (%s)" % (patient["firstName"],patient["lastName"],self.__carelink_patient_id))
else:
raise Exception("No patient found.")
printdbg("No patient found.")
if self.__session_user is None:
self.__session_user = await self.__get_my_user()
if self.__session_profile is None:
Expand Down Expand Up @@ -399,16 +400,13 @@ async def __refreshToken(self, token):


async def __get_authorization_token(self):
try:
auth_token = self.async_client.cookies[CARELINK_AUTH_TOKEN_COOKIE_NAME]
auth_token_validto = self.async_client.cookies[CARELINK_TOKEN_VALIDTO_COOKIE_NAME]
except:
auth_token = self.__carelink_auth_token
auth_token_validto = self.__auth_token_validto
auth_token = self.__carelink_auth_token
auth_token_validto = self.__auth_token_validto

if auth_token == None or auth_token_validto == None:
printdbg("No valid token")
return None

if auth_token == None or auth_token_validto == None:
printdbg("No valid token")
return None
if (datetime.strptime(auth_token_validto, '%a %b %d %H:%M:%S UTC %Y') - datetime.utcnow()) < timedelta(seconds=AUTH_EXPIRE_DEADLINE_MINUTES*60):
if await self.__refreshToken(auth_token):
self.__carelink_auth_token = self.async_client.cookies[CARELINK_AUTH_TOKEN_COOKIE_NAME]
Expand Down

0 comments on commit eae2c9e

Please sign in to comment.