Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The duotecno integration."""
2 
3 from __future__ import annotations
4 
5 from duotecno.controller import PyDuotecno
6 from duotecno.exceptions import InvalidPassword, LoadFailure
7 
8 from homeassistant.config_entries import ConfigEntry
9 from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, Platform
10 from homeassistant.core import HomeAssistant
11 from homeassistant.exceptions import ConfigEntryNotReady
12 
13 from .const import DOMAIN
14 
15 PLATFORMS: list[Platform] = [
16  Platform.BINARY_SENSOR,
17  Platform.CLIMATE,
18  Platform.COVER,
19  Platform.LIGHT,
20  Platform.SWITCH,
21 ]
22 
23 
24 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
25  """Set up duotecno from a config entry."""
26 
27  controller = PyDuotecno()
28  try:
29  await controller.connect(
30  entry.data[CONF_HOST], entry.data[CONF_PORT], entry.data[CONF_PASSWORD]
31  )
32  except (OSError, InvalidPassword, LoadFailure) as err:
33  raise ConfigEntryNotReady from err
34  hass.data.setdefault(DOMAIN, {})[entry.entry_id] = controller
35  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
36  return True
37 
38 
39 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
40  """Unload a config entry."""
41  if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
42  hass.data[DOMAIN].pop(entry.entry_id)
43 
44  return unload_ok
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:24
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:39