Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The statistics component."""
2 
3 from homeassistant.config_entries import ConfigEntry
4 from homeassistant.const import CONF_ENTITY_ID, Platform
5 from homeassistant.core import HomeAssistant
7  async_remove_stale_devices_links_keep_entity_device,
8 )
9 
10 DOMAIN = "statistics"
11 PLATFORMS = [Platform.SENSOR]
12 
13 
14 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
15  """Set up Statistics from a config entry."""
16 
18  hass,
19  entry.entry_id,
20  entry.options[CONF_ENTITY_ID],
21  )
22 
23  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
24  entry.async_on_unload(entry.add_update_listener(update_listener))
25 
26  return True
27 
28 
29 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
30  """Unload Statistics config entry."""
31  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
32 
33 
34 async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
35  """Handle options update."""
36  await hass.config_entries.async_reload(entry.entry_id)
None update_listener(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:34
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:29
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:14
None async_remove_stale_devices_links_keep_entity_device(HomeAssistant hass, str entry_id, str source_entity_id_or_uuid)
Definition: device.py:66