Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The PEGELONLINE component."""
2 
3 from __future__ import annotations
4 
5 import logging
6 
7 from aiopegelonline import PegelOnline
8 
9 from homeassistant.config_entries import ConfigEntry
10 from homeassistant.const import Platform
11 from homeassistant.core import HomeAssistant
12 from homeassistant.helpers.aiohttp_client import async_get_clientsession
13 
14 from .const import CONF_STATION
15 from .coordinator import PegelOnlineDataUpdateCoordinator
16 
17 _LOGGER = logging.getLogger(__name__)
18 
19 PLATFORMS = [Platform.SENSOR]
20 
21 type PegelOnlineConfigEntry = ConfigEntry[PegelOnlineDataUpdateCoordinator]
22 
23 
24 async def async_setup_entry(hass: HomeAssistant, entry: PegelOnlineConfigEntry) -> bool:
25  """Set up PEGELONLINE entry."""
26  station_uuid = entry.data[CONF_STATION]
27 
28  _LOGGER.debug("Setting up station with uuid %s", station_uuid)
29 
30  api = PegelOnline(async_get_clientsession(hass))
31  station = await api.async_get_station_details(station_uuid)
32 
33  coordinator = PegelOnlineDataUpdateCoordinator(hass, entry.title, api, station)
34 
35  await coordinator.async_config_entry_first_refresh()
36 
37  entry.runtime_data = coordinator
38 
39  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
40 
41  return True
42 
43 
44 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
45  """Unload PEGELONLINE entry."""
46  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_setup_entry(HomeAssistant hass, PegelOnlineConfigEntry entry)
Definition: __init__.py:24
bool async_unload_entry(HomeAssistant hass, ConfigEntry 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)