1 """Coordinator to update data from Aquacell API."""
4 from datetime
import datetime
7 from aioaquacell
import (
22 CONF_REFRESH_TOKEN_CREATION_TIME,
23 REFRESH_TOKEN_EXPIRY_TIME,
27 _LOGGER = logging.getLogger(__name__)
31 """My aquacell coordinator."""
33 config_entry: ConfigEntry
35 def __init__(self, hass: HomeAssistant, aquacell_api: AquacellApi) ->
None:
36 """Initialize coordinator."""
40 name=
"Aquacell Coordinator",
41 update_interval=UPDATE_INTERVAL,
46 CONF_REFRESH_TOKEN_CREATION_TIME
53 """Fetch data from API endpoint.
55 This is the place to pre-process the data to lookup tables
56 so entities can quickly look up their data.
59 async
with asyncio.timeout(30):
63 + REFRESH_TOKEN_EXPIRY_TIME.total_seconds()
66 if datetime.now().timestamp() >= expiry_time:
70 _LOGGER.debug(
"Logged in using: %s", self.
refresh_tokenrefresh_token)
72 softeners = await self.
aquacell_apiaquacell_api.get_all_softeners()
73 except AuthenticationFailed
as err:
74 raise ConfigEntryError
from err
75 except (AquacellApiException, TimeoutError)
as err:
76 raise UpdateFailed(f
"Error communicating with API: {err}")
from err
78 return {softener.dsn: softener
for softener
in softeners}
81 _LOGGER.debug(
"Attempting to renew refresh token")
87 CONF_REFRESH_TOKEN_CREATION_TIME: datetime.now().timestamp(),
90 self.
hasshass.config_entries.async_update_entry(self.
config_entryconfig_entry, data=data)
None _reauthenticate(self)
dict[str, Softener] _async_update_data(self)
refresh_token_creation_time
None __init__(self, HomeAssistant hass, AquacellApi aquacell_api)
def authenticate(HomeAssistant hass, host, port, servers)