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