diff --git a/custom_components/deebot/config_flow.py b/custom_components/deebot/config_flow.py index 2ee89cc..88cd1f9 100644 --- a/custom_components/deebot/config_flow.py +++ b/custom_components/deebot/config_flow.py @@ -5,9 +5,10 @@ import homeassistant.helpers.config_validation as cv import voluptuous as vol +from aiohttp import ClientError from deebotozmo.ecovacs_api import EcovacsAPI from deebotozmo.util import md5 -from homeassistant import config_entries, exceptions +from homeassistant import config_entries from homeassistant.const import CONF_MODE, CONF_DEVICES from homeassistant.helpers import aiohttp_client @@ -68,7 +69,7 @@ async def async_step_user(self, user_input=None): try: info = await self.async_retrieve_bots(user_input) self.robot_list = info - except CannotConnect as e: + except ClientError as e: _LOGGER.debug("Cannot connect", e, exc_info=True) errors["base"] = "cannot_connect" except ValueError as e: @@ -140,7 +141,3 @@ async def async_step_robots(self, user_input=None): return self.async_show_form( step_id="robots", data_schema=options_schema, errors=errors ) - - -class CannotConnect(exceptions.HomeAssistantError): - """Error to indicate we cannot connect.""" diff --git a/custom_components/deebot/hub.py b/custom_components/deebot/hub.py index 8f73143..7f18a22 100644 --- a/custom_components/deebot/hub.py +++ b/custom_components/deebot/hub.py @@ -5,6 +5,7 @@ from typing import Any, Mapping, Optional import aiohttp +from aiohttp import ClientError from deebotozmo.ecovacs_api import EcovacsAPI from deebotozmo.ecovacs_mqtt import EcovacsMqtt from deebotozmo.util import md5 @@ -100,8 +101,13 @@ def name(self): async def _check_status_task(self): while True: - await asyncio.sleep(60) - await self._check_status_function() + try: + await asyncio.sleep(60) + await self._check_status_function() + except ClientError as e: + _LOGGER.warning(f"A client error occurred, probably the ecovacs servers are unstable: {e}") + except Exception as e: + _LOGGER.error(f"Unknown exception occurred: {e}") async def _check_status_function(self): devices = await self._ecovacs_api.get_devices()