Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The buienradar integration."""
2 
3 from __future__ import annotations
4 
5 from homeassistant.config_entries import ConfigEntry
6 from homeassistant.const import Platform
7 from homeassistant.core import HomeAssistant
8 
9 from .util import BrData
10 
11 PLATFORMS = [Platform.CAMERA, Platform.SENSOR, Platform.WEATHER]
12 
13 type BuienRadarConfigEntry = ConfigEntry[dict[Platform, BrData]]
14 
15 
16 async def async_setup_entry(hass: HomeAssistant, entry: BuienRadarConfigEntry) -> bool:
17  """Set up buienradar from a config entry."""
18  entry.runtime_data = {}
19  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
20  entry.async_on_unload(entry.add_update_listener(async_update_options))
21  return True
22 
23 
24 async def async_unload_entry(hass: HomeAssistant, entry: BuienRadarConfigEntry) -> bool:
25  """Unload a config entry."""
26  if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
27  for platform in PLATFORMS:
28  if (data := entry.runtime_data.get(platform)) and (
29  unsub := data.unsub_schedule_update
30  ):
31  unsub()
32 
33  return unload_ok
34 
35 
37  hass: HomeAssistant, config_entry: BuienRadarConfigEntry
38 ) -> None:
39  """Update options."""
40  await hass.config_entries.async_reload(config_entry.entry_id)
bool async_setup_entry(HomeAssistant hass, BuienRadarConfigEntry entry)
Definition: __init__.py:16
bool async_unload_entry(HomeAssistant hass, BuienRadarConfigEntry entry)
Definition: __init__.py:24
None async_update_options(HomeAssistant hass, BuienRadarConfigEntry config_entry)
Definition: __init__.py:38