Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """Support for The Things network."""
2 
3 import logging
4 
5 from homeassistant.config_entries import ConfigEntry
6 from homeassistant.const import CONF_API_KEY, CONF_HOST
7 from homeassistant.core import HomeAssistant
8 
9 from .const import DOMAIN, PLATFORMS, TTN_API_HOST
10 from .coordinator import TTNCoordinator
11 
12 _LOGGER = logging.getLogger(__name__)
13 
14 
15 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
16  """Establish connection with The Things Network."""
17 
18  _LOGGER.debug(
19  "Set up %s at %s",
20  entry.data[CONF_API_KEY],
21  entry.data.get(CONF_HOST, TTN_API_HOST),
22  )
23 
24  coordinator = TTNCoordinator(hass, entry)
25 
26  await coordinator.async_config_entry_first_refresh()
27 
28  hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
29 
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 a config entry."""
37 
38  _LOGGER.debug(
39  "Remove %s at %s",
40  entry.data[CONF_API_KEY],
41  entry.data.get(CONF_HOST, TTN_API_HOST),
42  )
43 
44  # Unload entities created for each supported platform
45  unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
46  if unload_ok:
47  del hass.data[DOMAIN][entry.entry_id]
48  return True
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:15
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:35