Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Airgradient integration."""
2 
3 from __future__ import annotations
4 
5 from airgradient import AirGradientClient
6 
7 from homeassistant.config_entries import ConfigEntry
8 from homeassistant.const import CONF_HOST, Platform
9 from homeassistant.core import HomeAssistant
10 from homeassistant.helpers.aiohttp_client import async_get_clientsession
11 
12 from .coordinator import AirGradientCoordinator
13 
14 PLATFORMS: list[Platform] = [
15  Platform.BUTTON,
16  Platform.NUMBER,
17  Platform.SELECT,
18  Platform.SENSOR,
19  Platform.SWITCH,
20  Platform.UPDATE,
21 ]
22 
23 
24 type AirGradientConfigEntry = ConfigEntry[AirGradientCoordinator]
25 
26 
27 async def async_setup_entry(hass: HomeAssistant, entry: AirGradientConfigEntry) -> bool:
28  """Set up Airgradient from a config entry."""
29 
30  client = AirGradientClient(
31  entry.data[CONF_HOST], session=async_get_clientsession(hass)
32  )
33 
34  coordinator = AirGradientCoordinator(hass, client)
35 
36  await coordinator.async_config_entry_first_refresh()
37 
38  entry.runtime_data = coordinator
39 
40  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
41 
42  return True
43 
44 
46  hass: HomeAssistant, entry: AirGradientConfigEntry
47 ) -> bool:
48  """Unload a config entry."""
49  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_unload_entry(HomeAssistant hass, AirGradientConfigEntry entry)
Definition: __init__.py:47
bool async_setup_entry(HomeAssistant hass, AirGradientConfigEntry entry)
Definition: __init__.py:27
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)