Fixed initialization with API but no internet.

This commit is contained in:
Neal Joslin
2023-07-25 23:17:59 -04:00
parent f06e4848e6
commit 62011a9d6b
2 changed files with 7 additions and 3 deletions

View File

@@ -255,6 +255,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
res = await tuya_api.async_get_access_token() res = await tuya_api.async_get_access_token()
if res != "ok": if res != "ok":
_LOGGER.error("Cloud API connection failed: %s", res) _LOGGER.error("Cloud API connection failed: %s", res)
else:
_LOGGER.info("Cloud API connection succeeded.") _LOGGER.info("Cloud API connection succeeded.")
res = await tuya_api.async_get_devices_list() res = await tuya_api.async_get_devices_list()
hass.data[DOMAIN][DATA_CLOUD] = tuya_api hass.data[DOMAIN][DATA_CLOUD] = tuya_api

View File

@@ -101,7 +101,10 @@ class TuyaCloudApi:
async def async_get_access_token(self): async def async_get_access_token(self):
"""Obtain a valid access token.""" """Obtain a valid access token."""
try:
resp = await self.async_make_request("GET", "/v1.0/token?grant_type=1") resp = await self.async_make_request("GET", "/v1.0/token?grant_type=1")
except requests.exceptions.ConnectionError:
return "Request failed, status ConnectionError"
if not resp.ok: if not resp.ok:
return "Request failed, status " + str(resp.status) return "Request failed, status " + str(resp.status)