Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """Support for RDW."""
2 
3 from __future__ import annotations
4 
5 from vehicle import RDW, Vehicle
6 
7 from homeassistant.config_entries import ConfigEntry
8 from homeassistant.const import Platform
9 from homeassistant.core import HomeAssistant
10 from homeassistant.helpers.aiohttp_client import async_get_clientsession
11 from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
12 
13 from .const import CONF_LICENSE_PLATE, DOMAIN, LOGGER, SCAN_INTERVAL
14 
15 PLATFORMS = [Platform.BINARY_SENSOR, Platform.SENSOR]
16 
17 
18 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
19  """Set up RDW from a config entry."""
20  session = async_get_clientsession(hass)
21  rdw = RDW(session=session, license_plate=entry.data[CONF_LICENSE_PLATE])
22 
23  coordinator: DataUpdateCoordinator[Vehicle] = DataUpdateCoordinator(
24  hass,
25  LOGGER,
26  config_entry=entry,
27  name=f"{DOMAIN}_APK",
28  update_interval=SCAN_INTERVAL,
29  update_method=rdw.vehicle,
30  )
31  await coordinator.async_config_entry_first_refresh()
32 
33  hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
34  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
35 
36  return True
37 
38 
39 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
40  """Unload RDW config entry."""
41  unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
42  if unload_ok:
43  del hass.data[DOMAIN][entry.entry_id]
44  return unload_ok
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:39
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:18
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)