1 """Data update coordinator for shark iq vacuums."""
3 from __future__
import annotations
6 from datetime
import datetime, timedelta
11 SharkIqAuthExpiringError,
12 SharkIqNotAuthedError,
21 from .const
import API_TIMEOUT, DOMAIN, LOGGER, UPDATE_INTERVAL
25 """Define a wrapper class to update Shark IQ data."""
30 config_entry: ConfigEntry,
32 shark_vacs: list[SharkIqVacuum],
34 """Set up the SharkIqUpdateCoordinator class."""
36 self.shark_vacs: dict[str, SharkIqVacuum] = {
37 sharkiq.serial_number: sharkiq
for sharkiq
in shark_vacs
42 super().
__init__(hass, LOGGER, name=DOMAIN, update_interval=UPDATE_INTERVAL)
46 """Get the set of all online DSNs."""
50 """Return the online state of a given vacuum dsn."""
55 """Asynchronously update the data for a single vacuum."""
56 dsn = sharkiq.serial_number
57 LOGGER.debug(
"Updating sharkiq data for device DSN %s", dsn)
58 async
with asyncio.timeout(API_TIMEOUT):
59 await sharkiq.async_update()
62 """Update data device by device."""
65 self.
ayla_apiayla_api.token_expiring_soon
69 await self.
ayla_apiayla_api.async_refresh_auth()
71 all_vacuums = await self.
ayla_apiayla_api.async_list_devices()
75 if v[
"connection_status"] ==
"Online" and v[
"dsn"]
in self.shark_vacs
78 LOGGER.debug(
"Updating sharkiq data")
79 online_vacs = (self.shark_vacs[dsn]
for dsn
in self.
online_dsnsonline_dsns)
83 SharkIqNotAuthedError,
84 SharkIqAuthExpiringError,
86 LOGGER.debug(
"Bad auth state. Attempting re-auth", exc_info=err)
87 raise ConfigEntryAuthFailed
from err
88 except Exception
as err:
89 LOGGER.exception(
"Unexpected error updating SharkIQ. Attempting re-auth")
set[str] online_dsns(self)
bool device_is_online(self, str dsn)
bool _async_update_data(self)
None _async_update_vacuum(SharkIqVacuum sharkiq)
None __init__(self, HomeAssistant hass, ConfigEntry config_entry, AylaApi ayla_api, list[SharkIqVacuum] shark_vacs)