1 """The GeoJSON events component."""
3 from __future__
import annotations
12 from .const
import DOMAIN, PLATFORMS
13 from .manager
import GeoJsonFeedEntityManager
15 _LOGGER = logging.getLogger(__name__)
19 """Set up the GeoJSON events component as config entry."""
20 feeds = hass.data.setdefault(DOMAIN, {})
23 feeds[config_entry.entry_id] = manager
24 _LOGGER.debug(
"Feed entity manager added for %s", config_entry.entry_id)
26 await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
27 await manager.async_init()
32 """Remove orphaned geo_location entities.
34 This is needed because when fetching data from the external feed this integration is
35 determining which entities need to be added, updated or removed by comparing the
36 current with the previous data. After a restart of Home Assistant the integration
37 has no previous data to compare against, and thus all entities managed by this
38 integration are removed after startup.
40 entity_registry = er.async_get(hass)
41 orphaned_entries = er.async_entries_for_config_entry(entity_registry, entry_id)
42 if orphaned_entries
is not None:
43 for entry
in orphaned_entries:
44 if entry.domain == Platform.GEO_LOCATION:
45 _LOGGER.debug(
"Removing orphaned entry %s", entry.entity_id)
46 entity_registry.async_remove(entry.entity_id)
50 """Unload the GeoJSON events config entry."""
51 unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
53 manager: GeoJsonFeedEntityManager = hass.data[DOMAIN].pop(entry.entry_id)
54 await manager.async_stop()
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
None remove_orphaned_entities(HomeAssistant hass, str entry_id)
bool async_setup_entry(HomeAssistant hass, ConfigEntry config_entry)