Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The air-Q 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 .const import CONF_CLIP_NEGATIVE, CONF_RETURN_AVERAGE
10 from .coordinator import AirQCoordinator
11 
12 PLATFORMS: list[Platform] = [Platform.SENSOR]
13 
14 AirQConfigEntry = ConfigEntry[AirQCoordinator]
15 
16 
17 async def async_setup_entry(hass: HomeAssistant, entry: AirQConfigEntry) -> bool:
18  """Set up air-Q from a config entry."""
19 
20  coordinator = AirQCoordinator(
21  hass,
22  entry,
23  clip_negative=entry.options.get(CONF_CLIP_NEGATIVE, True),
24  return_average=entry.options.get(CONF_RETURN_AVERAGE, True),
25  )
26 
27  # Query the device for the first time and initialise coordinator.data
28  await coordinator.async_config_entry_first_refresh()
29 
30  entry.runtime_data = coordinator
31 
32  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
33  entry.async_on_unload(entry.add_update_listener(update_listener))
34 
35  return True
36 
37 
38 async def async_unload_entry(hass: HomeAssistant, entry: AirQConfigEntry) -> bool:
39  """Unload a config entry."""
40  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
41 
42 
43 async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
44  """Handle options update."""
45  await hass.config_entries.async_reload(entry.entry_id)
None update_listener(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:43
bool async_unload_entry(HomeAssistant hass, AirQConfigEntry entry)
Definition: __init__.py:38
bool async_setup_entry(HomeAssistant hass, AirQConfigEntry entry)
Definition: __init__.py:17