Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The awair component."""
2 
3 from __future__ import annotations
4 
5 from homeassistant.const import CONF_HOST, Platform
6 from homeassistant.core import HomeAssistant
7 from homeassistant.helpers.aiohttp_client import async_get_clientsession
8 
9 from .coordinator import (
10  AwairCloudDataUpdateCoordinator,
11  AwairConfigEntry,
12  AwairDataUpdateCoordinator,
13  AwairLocalDataUpdateCoordinator,
14 )
15 
16 PLATFORMS = [Platform.SENSOR]
17 
18 
20  hass: HomeAssistant, config_entry: AwairConfigEntry
21 ) -> bool:
22  """Set up Awair integration from a config entry."""
23  session = async_get_clientsession(hass)
24 
25  coordinator: AwairDataUpdateCoordinator
26 
27  if CONF_HOST in config_entry.data:
28  coordinator = AwairLocalDataUpdateCoordinator(hass, config_entry, session)
29  config_entry.async_on_unload(
30  config_entry.add_update_listener(_async_update_listener)
31  )
32  else:
33  coordinator = AwairCloudDataUpdateCoordinator(hass, config_entry, session)
34 
35  await coordinator.async_config_entry_first_refresh()
36 
37  config_entry.runtime_data = coordinator
38 
39  await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
40 
41  return True
42 
43 
44 async def _async_update_listener(hass: HomeAssistant, entry: AwairConfigEntry) -> None:
45  """Handle options update."""
46  if entry.title != entry.runtime_data.title:
47  await hass.config_entries.async_reload(entry.entry_id)
48 
49 
51  hass: HomeAssistant, config_entry: AwairConfigEntry
52 ) -> bool:
53  """Unload Awair configuration."""
54  return await hass.config_entries.async_unload_platforms(config_entry, PLATFORMS)
bool async_unload_entry(HomeAssistant hass, AwairConfigEntry config_entry)
Definition: __init__.py:52
bool async_setup_entry(HomeAssistant hass, AwairConfigEntry config_entry)
Definition: __init__.py:21
None _async_update_listener(HomeAssistant hass, AwairConfigEntry entry)
Definition: __init__.py:44
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)