1 """UK Environment Agency Flood Monitoring Integration."""
4 from datetime
import timedelta
8 from aioeafm
import get_station
16 from .const
import DOMAIN
18 PLATFORMS = [Platform.SENSOR]
20 _LOGGER = logging.getLogger(__name__)
24 """Force measure key to always be a list."""
25 if "measures" not in station_data:
27 if isinstance(station_data[
"measures"], dict):
28 return [station_data[
"measures"]]
29 return station_data[
"measures"]
33 """Set up flood monitoring sensors for this config entry."""
34 station_key = entry.data[
"station"]
37 async
def _async_update_data() -> dict[str, dict[str, Any]]:
39 async
with asyncio.timeout(30):
40 data = await get_station(session, station_key)
45 data[
"measures"] = {measure[
"@id"]: measure
for measure
in measures}
48 coordinator = DataUpdateCoordinator[dict[str, dict[str, Any]]](
53 update_method=_async_update_data,
54 update_interval=
timedelta(seconds=15 * 60),
56 await coordinator.async_config_entry_first_refresh()
57 hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
58 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
63 """Unload flood monitoring sensors."""
64 return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
def get_measures(station_data)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)