Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Lektrico Charging Station integration."""
2 
3 from __future__ import annotations
4 
5 from lektricowifi import Device
6 
7 from homeassistant.config_entries import ConfigEntry
8 from homeassistant.const import ATTR_SERIAL_NUMBER, CONF_TYPE, Platform
9 from homeassistant.core import HomeAssistant
10 
11 from .coordinator import LektricoDeviceDataUpdateCoordinator
12 
13 # List the platforms that charger supports.
14 CHARGERS_PLATFORMS: list[Platform] = [
15  Platform.BINARY_SENSOR,
16  Platform.BUTTON,
17  Platform.NUMBER,
18  Platform.SENSOR,
19  Platform.SWITCH,
20 ]
21 
22 # List the platforms that load balancer device supports.
23 LB_DEVICES_PLATFORMS: list[Platform] = [
24  Platform.BUTTON,
25  Platform.SELECT,
26  Platform.SENSOR,
27 ]
28 
29 type LektricoConfigEntry = ConfigEntry[LektricoDeviceDataUpdateCoordinator]
30 
31 
32 async def async_setup_entry(hass: HomeAssistant, entry: LektricoConfigEntry) -> bool:
33  """Set up Lektrico Charging Station from a config entry."""
35  hass,
36  f"{entry.data[CONF_TYPE]}_{entry.data[ATTR_SERIAL_NUMBER]}",
37  )
38 
39  await coordinator.async_config_entry_first_refresh()
40 
41  entry.runtime_data = coordinator
42 
43  await hass.config_entries.async_forward_entry_setups(entry, _get_platforms(entry))
44 
45  return True
46 
47 
48 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
49  """Unload a config entry."""
50 
51  return await hass.config_entries.async_unload_platforms(
52  entry, _get_platforms(entry)
53  )
54 
55 
56 def _get_platforms(entry: ConfigEntry) -> list[Platform]:
57  """Return the platforms for this type of device."""
58  _device_type: str = entry.data[CONF_TYPE]
59  if _device_type in (Device.TYPE_1P7K, Device.TYPE_3P22K):
60  return CHARGERS_PLATFORMS
61  return LB_DEVICES_PLATFORMS
bool async_setup_entry(HomeAssistant hass, LektricoConfigEntry entry)
Definition: __init__.py:32
list[Platform] _get_platforms(ConfigEntry entry)
Definition: __init__.py:56
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:48