Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The aurora component."""
2 
3 from homeassistant.config_entries import ConfigEntry
4 from homeassistant.const import Platform
5 from homeassistant.core import HomeAssistant
6 
7 from .const import CONF_THRESHOLD, DEFAULT_THRESHOLD
8 from .coordinator import AuroraDataUpdateCoordinator
9 
10 PLATFORMS = [Platform.BINARY_SENSOR, Platform.SENSOR]
11 
12 type AuroraConfigEntry = ConfigEntry[AuroraDataUpdateCoordinator]
13 
14 
15 async def async_setup_entry(hass: HomeAssistant, entry: AuroraConfigEntry) -> bool:
16  """Set up Aurora from a config entry."""
17  coordinator = AuroraDataUpdateCoordinator(hass=hass)
18 
19  await coordinator.async_config_entry_first_refresh()
20 
21  entry.runtime_data = coordinator
22 
23  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
24 
25  entry.async_on_unload(entry.add_update_listener(update_listener))
26  return True
27 
28 
29 async def update_listener(hass: HomeAssistant, entry: AuroraConfigEntry) -> None:
30  """Handle options update."""
31  entry.runtime_data.threshold = int(
32  entry.options.get(CONF_THRESHOLD, DEFAULT_THRESHOLD)
33  )
34  # refresh the state of the visibility alert binary sensor
35  await entry.runtime_data.async_request_refresh()
36 
37 
38 async def async_unload_entry(hass: HomeAssistant, entry: AuroraConfigEntry) -> bool:
39  """Unload a config entry."""
40  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_setup_entry(HomeAssistant hass, AuroraConfigEntry entry)
Definition: __init__.py:15
None update_listener(HomeAssistant hass, AuroraConfigEntry entry)
Definition: __init__.py:29
bool async_unload_entry(HomeAssistant hass, AuroraConfigEntry entry)
Definition: __init__.py:38