Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Flexit Nordic (BACnet) integration."""
2 
3 from __future__ import annotations
4 
5 from homeassistant.config_entries import ConfigEntry
6 from homeassistant.const import CONF_DEVICE_ID, Platform
7 from homeassistant.core import HomeAssistant
8 
9 from .const import DOMAIN
10 from .coordinator import FlexitCoordinator
11 
12 PLATFORMS: list[Platform] = [
13  Platform.BINARY_SENSOR,
14  Platform.CLIMATE,
15  Platform.NUMBER,
16  Platform.SENSOR,
17  Platform.SWITCH,
18 ]
19 
20 
21 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
22  """Set up Flexit Nordic (BACnet) from a config entry."""
23 
24  device_id = entry.data[CONF_DEVICE_ID]
25 
26  coordinator = FlexitCoordinator(hass, device_id)
27  await coordinator.async_config_entry_first_refresh()
28 
29  hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
30  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
31 
32  return True
33 
34 
35 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
36  """Unload the Flexit Nordic (BACnet) config entry."""
37  if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
38  hass.data[DOMAIN].pop(entry.entry_id)
39 
40  return unload_ok
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:35
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:21