Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Integration integration."""
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
9  async_remove_stale_devices_links_keep_entity_device,
10 )
11 
12 from .const import CONF_SOURCE_SENSOR
13 
14 
15 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
16  """Set up Integration from a config entry."""
17 
19  hass,
20  entry.entry_id,
21  entry.options[CONF_SOURCE_SENSOR],
22  )
23 
24  await hass.config_entries.async_forward_entry_setups(entry, (Platform.SENSOR,))
25  entry.async_on_unload(entry.add_update_listener(config_entry_update_listener))
26  return True
27 
28 
29 async def config_entry_update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
30  """Update listener, called when the config entry options are changed."""
31  # Remove device link for entry, the source device may have changed.
32  # The link will be recreated after load.
33  await hass.config_entries.async_reload(entry.entry_id)
34 
35 
36 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
37  """Unload a config entry."""
38  return await hass.config_entries.async_unload_platforms(entry, (Platform.SENSOR,))
None config_entry_update_listener(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:29
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:15
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:36
None async_remove_stale_devices_links_keep_entity_device(HomeAssistant hass, str entry_id, str source_entity_id_or_uuid)
Definition: device.py:66