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