diff --git a/custom_components/localtuya/__init__.py b/custom_components/localtuya/__init__.py index 9a996c3..a72b842 100644 --- a/custom_components/localtuya/__init__.py +++ b/custom_components/localtuya/__init__.py @@ -255,8 +255,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): res = await tuya_api.async_get_access_token() if res != "ok": _LOGGER.error("Cloud API connection failed: %s", res) - _LOGGER.info("Cloud API connection succeeded.") - res = await tuya_api.async_get_devices_list() + else: + _LOGGER.info("Cloud API connection succeeded.") + res = await tuya_api.async_get_devices_list() hass.data[DOMAIN][DATA_CLOUD] = tuya_api async def setup_entities(device_ids): diff --git a/custom_components/localtuya/cloud_api.py b/custom_components/localtuya/cloud_api.py index 6802171..a0c5128 100644 --- a/custom_components/localtuya/cloud_api.py +++ b/custom_components/localtuya/cloud_api.py @@ -101,7 +101,10 @@ class TuyaCloudApi: async def async_get_access_token(self): """Obtain a valid access token.""" - resp = await self.async_make_request("GET", "/v1.0/token?grant_type=1") + try: + 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: return "Request failed, status " + str(resp.status)