Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The sia integration."""
2 
3 from homeassistant.config_entries import ConfigEntry
4 from homeassistant.const import CONF_PORT
5 from homeassistant.core import HomeAssistant
6 from homeassistant.exceptions import ConfigEntryNotReady
7 
8 from .const import DOMAIN, PLATFORMS
9 from .hub import SIAHub
10 
11 
12 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
13  """Set up sia from a config entry."""
14  hub: SIAHub = SIAHub(hass, entry)
15  hub.async_setup_hub()
16 
17  hass.data.setdefault(DOMAIN, {})
18  hass.data[DOMAIN][entry.entry_id] = hub
19  try:
20  if hub.sia_client:
21  await hub.sia_client.async_start(reuse_port=True)
22  except OSError as exc:
23  raise ConfigEntryNotReady(
24  f"SIA Server at port {entry.data[CONF_PORT]} could not start."
25  ) from exc
26  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
27  return True
28 
29 
30 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
31  """Unload a config entry."""
32  unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
33  if unload_ok:
34  hub: SIAHub = hass.data[DOMAIN].pop(entry.entry_id)
35  await hub.async_shutdown()
36  return unload_ok
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:30
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:12