Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The qnap component."""
2 
3 from __future__ import annotations
4 
5 from homeassistant.config_entries import ConfigEntry
6 from homeassistant.const import Platform
7 from homeassistant.core import HomeAssistant
8 
9 from .const import DOMAIN
10 from .coordinator import QnapCoordinator
11 
12 PLATFORMS: list[Platform] = [
13  Platform.SENSOR,
14 ]
15 
16 
17 async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
18  """Set the config entry up."""
19  hass.data.setdefault(DOMAIN, {})
20  coordinator = QnapCoordinator(hass, config_entry)
21  # Fetch initial data so we have data when entities subscribe
22  await coordinator.async_config_entry_first_refresh()
23  hass.data[DOMAIN][config_entry.entry_id] = coordinator
24  await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
25  return True
26 
27 
28 async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
29  """Unload a config entry."""
30  if unload_ok := await hass.config_entries.async_unload_platforms(
31  config_entry, PLATFORMS
32  ):
33  hass.data[DOMAIN].pop(config_entry.entry_id)
34  return unload_ok
bool async_unload_entry(HomeAssistant hass, ConfigEntry config_entry)
Definition: __init__.py:28
bool async_setup_entry(HomeAssistant hass, ConfigEntry config_entry)
Definition: __init__.py:17