Skip to content
Snippets Groups Projects
Commit de1799d4 authored by Florent Thoumie's avatar Florent Thoumie Committed by Fabian Affolter
Browse files

iaqualink: better handling of failures (#28514)

parent 60d7f730
Branches
Tags
No related merge requests found
...@@ -4,6 +4,7 @@ from functools import wraps ...@@ -4,6 +4,7 @@ from functools import wraps
import logging import logging
from typing import Any, Dict from typing import Any, Dict
import aiohttp.client_exceptions
import voluptuous as vol import voluptuous as vol
from iaqualink import ( from iaqualink import (
...@@ -26,6 +27,7 @@ from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN ...@@ -26,6 +27,7 @@ from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.dispatcher import ( from homeassistant.helpers.dispatcher import (
async_dispatcher_connect, async_dispatcher_connect,
...@@ -90,8 +92,14 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> None ...@@ -90,8 +92,14 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> None
try: try:
await aqualink.login() await aqualink.login()
except AqualinkLoginException as login_exception: except AqualinkLoginException as login_exception:
_LOGGER.error("Exception raised while attempting to login: %s", login_exception) _LOGGER.error("Failed to login: %s", login_exception)
return False return False
except (
asyncio.TimeoutError,
aiohttp.client_exceptions.ClientConnectorError,
) as aio_exception:
_LOGGER.warning("Exception raised while attempting to login: %s", aio_exception)
raise ConfigEntryNotReady
systems = await aqualink.get_systems() systems = await aqualink.get_systems()
systems = list(systems.values()) systems = list(systems.values())
...@@ -133,7 +141,16 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> None ...@@ -133,7 +141,16 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> None
async def _async_systems_update(now): async def _async_systems_update(now):
"""Refresh internal state for all systems.""" """Refresh internal state for all systems."""
prev = systems[0].last_run_success
await systems[0].update() await systems[0].update()
success = systems[0].last_run_success
if not success and prev:
_LOGGER.warning("Failed to refresh iAqualink state")
elif success and not prev:
_LOGGER.warning("Reconnected to iAqualink")
async_dispatcher_send(hass, DOMAIN) async_dispatcher_send(hass, DOMAIN)
async_track_time_interval(hass, _async_systems_update, UPDATE_INTERVAL) async_track_time_interval(hass, _async_systems_update, UPDATE_INTERVAL)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment