Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Sensoterra integration."""
2 
3 from __future__ import annotations
4 
5 from sensoterra.customerapi import CustomerApi
6 
7 from homeassistant.config_entries import ConfigEntry
8 from homeassistant.const import CONF_TOKEN, Platform
9 from homeassistant.core import HomeAssistant
10 
11 from .coordinator import SensoterraCoordinator
12 
13 PLATFORMS: list[Platform] = [Platform.SENSOR]
14 
15 type SensoterraConfigEntry = ConfigEntry[SensoterraCoordinator]
16 
17 
18 async def async_setup_entry(hass: HomeAssistant, entry: SensoterraConfigEntry) -> bool:
19  """Set up Sensoterra platform based on a configuration entry."""
20 
21  # Create a coordinator and add an API instance to it. Store the coordinator
22  # in the configuration entry.
23  api = CustomerApi()
24  api.set_language(hass.config.language)
25  api.set_token(entry.data[CONF_TOKEN])
26 
27  coordinator = SensoterraCoordinator(hass, api)
28  await coordinator.async_config_entry_first_refresh()
29  entry.runtime_data = coordinator
30 
31  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
32 
33  return True
34 
35 
36 async def async_unload_entry(hass: HomeAssistant, entry: SensoterraConfigEntry) -> bool:
37  """Unload the configuration entry."""
38  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_unload_entry(HomeAssistant hass, SensoterraConfigEntry entry)
Definition: __init__.py:36
bool async_setup_entry(HomeAssistant hass, SensoterraConfigEntry entry)
Definition: __init__.py:18