1 """The nVent RAYCHEM SENZ integration."""
3 from __future__
import annotations
5 from datetime
import timedelta
8 from aiosenz
import SENZAPI, Thermostat
9 from httpx
import RequestError
16 config_entry_oauth2_flow,
17 config_validation
as cv,
22 from .api
import SENZConfigEntryAuth
23 from .const
import DOMAIN
27 _LOGGER = logging.getLogger(__name__)
29 CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
31 PLATFORMS = [Platform.CLIMATE]
33 type SENZDataUpdateCoordinator = DataUpdateCoordinator[dict[str, Thermostat]]
37 """Set up SENZ from a config entry."""
39 await config_entry_oauth2_flow.async_get_config_entry_implementation(
43 session = config_entry_oauth2_flow.OAuth2Session(hass, entry, implementation)
45 senz_api = SENZAPI(auth)
47 async
def update_thermostats() -> dict[str, Thermostat]:
48 """Fetch SENZ thermostats data."""
50 thermostats = await senz_api.get_thermostats()
51 except RequestError
as err:
52 raise UpdateFailed
from err
53 return {thermostat.serial_number: thermostat
for thermostat
in thermostats}
56 account = await senz_api.get_account()
57 except RequestError
as err:
58 raise ConfigEntryNotReady
from err
64 name=account.username,
65 update_interval=UPDATE_INTERVAL,
66 update_method=update_thermostats,
69 await coordinator.async_config_entry_first_refresh()
71 hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
73 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
79 """Unload a config entry."""
80 if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
81 hass.data[DOMAIN].pop(entry.entry_id)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)