Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The APsystems local API integration."""
2 
3 from __future__ import annotations
4 
5 from dataclasses import dataclass
6 
7 from APsystemsEZ1 import APsystemsEZ1M
8 
9 from homeassistant.config_entries import ConfigEntry
10 from homeassistant.const import CONF_IP_ADDRESS, CONF_PORT, Platform
11 from homeassistant.core import HomeAssistant
12 
13 from .const import DEFAULT_PORT
14 from .coordinator import ApSystemsDataCoordinator
15 
16 PLATFORMS: list[Platform] = [
17  Platform.BINARY_SENSOR,
18  Platform.NUMBER,
19  Platform.SENSOR,
20  Platform.SWITCH,
21 ]
22 
23 
24 @dataclass
26  """Store runtime data."""
27 
28  coordinator: ApSystemsDataCoordinator
29  device_id: str
30 
31 
32 type ApSystemsConfigEntry = ConfigEntry[ApSystemsData]
33 
34 
35 async def async_setup_entry(hass: HomeAssistant, entry: ApSystemsConfigEntry) -> bool:
36  """Set up this integration using UI."""
37  api = APsystemsEZ1M(
38  ip_address=entry.data[CONF_IP_ADDRESS],
39  port=entry.data.get(CONF_PORT, DEFAULT_PORT),
40  timeout=8,
41  enable_debounce=True,
42  )
43  coordinator = ApSystemsDataCoordinator(hass, api)
44  await coordinator.async_config_entry_first_refresh()
45  assert entry.unique_id
46  entry.runtime_data = ApSystemsData(
47  coordinator=coordinator, device_id=entry.unique_id
48  )
49  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
50 
51  return True
52 
53 
54 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
55  """Unload a config entry."""
56  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_setup_entry(HomeAssistant hass, ApSystemsConfigEntry entry)
Definition: __init__.py:35
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:54