mirror of
https://github.com/home-assistant/core.git
synced 2025-05-29 10:17:08 +00:00
iaqualink: better handling of failures (#28514)
This commit is contained in:
parent
60d7f730c3
commit
de1799d486
@ -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
|
|||||||
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
|
|||||||
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
|
|||||||
|
|
||||||
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user