Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Improve ClientError handling #182

Merged
merged 1 commit into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions custom_components/deebot/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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."""
10 changes: 8 additions & 2 deletions custom_components/deebot/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down