1 """Suez water update coordinator."""
3 from collections.abc
import Mapping
4 from dataclasses
import dataclass
5 from datetime
import date
8 from pysuez
import PySuezError, SuezClient
16 from .const
import CONF_COUNTER_ID, DATA_REFRESH_INTERVAL, DOMAIN
21 """Class containing aggregated sensor extra attributes."""
23 this_month_consumption: dict[date, float]
24 previous_month_consumption: dict[date, float]
25 last_year_overall: dict[str, float]
26 this_year_overall: dict[str, float]
27 history: dict[date, float]
28 highest_monthly_consumption: float
33 """Class used to hold all fetch data from suez api."""
35 aggregated_value: float
36 aggregated_attr: Mapping[str, Any]
41 """Suez water coordinator."""
43 _suez_client: SuezClient
44 config_entry: ConfigEntry
46 def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) ->
None:
47 """Initialize suez water coordinator."""
52 update_interval=DATA_REFRESH_INTERVAL,
54 config_entry=config_entry,
59 username=self.
config_entryconfig_entry.data[CONF_USERNAME],
60 password=self.
config_entryconfig_entry.data[CONF_PASSWORD],
61 counter_id=self.
config_entryconfig_entry.data[CONF_COUNTER_ID],
63 if not await self.
_suez_client_suez_client.check_credentials():
67 """Fetch data from API endpoint."""
69 aggregated = await self.
_suez_client_suez_client.fetch_aggregated_data()
71 aggregated_value=aggregated.value,
73 "this_month_consumption": aggregated.current_month,
74 "previous_month_consumption": aggregated.previous_month,
75 "highest_monthly_consumption": aggregated.highest_monthly_consumption,
76 "last_year_overall": aggregated.previous_year,
77 "this_year_overall": aggregated.current_year,
78 "history": aggregated.history,
80 price=(await self.
_suez_client_suez_client.get_price()).price,
82 except PySuezError
as err:
83 _LOGGER.exception(err)
85 f
"Suez coordinator error communicating with API: {err}"
87 _LOGGER.debug(
"Successfully fetched suez data")
SuezWaterData _async_update_data(self)
None __init__(self, HomeAssistant hass, ConfigEntry config_entry)