Skip to content

Commit

Permalink
Handle errror if refresh token failed
Browse files Browse the repository at this point in the history
  • Loading branch information
xZetsubou committed Oct 28, 2023
1 parent d372d42 commit a00d265
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion custom_components/localtuya/cloud_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ async def async_make_request(self, method, url, body=None, headers={}):
"""Perform requests."""
# obtain new token if expired.
if not self.token_validate and self._token_expire_time != -1:
await self.async_get_access_token()
if (res := await self.async_get_access_token()) and res != "ok":
return _LOGGER.debug(f"Refresh Token failed due to: {res}")

timestamp = str(int(time.time() * 1000))
payload = self.generate_payload(method, timestamp, url, headers, body)
Expand Down Expand Up @@ -115,6 +116,7 @@ async def async_get_access_token(self):
try:
resp = await self.async_make_request("GET", "/v1.0/token?grant_type=1")
except requests.exceptions.ConnectionError:
self._token_expire_time = 0
return "Request failed, status ConnectionError"

if not resp.ok:
Expand Down

0 comments on commit a00d265

Please sign in to comment.