361 files

This commit is contained in:
Home Assistant Version Control
2026-10-06 17:11:43 +00:00
parent d2c5af43e3
commit bf886c9347
362 changed files with 22060 additions and 1285 deletions
+31 -2
View File
@@ -18,6 +18,7 @@ from homeassistant.helpers import issue_registry as ir
from .automation_runs import async_setup_automation_runs
from .const import DOMAIN, LOGGER, PLATFORMS
from .dismissals import async_setup_dismissals
from .entity_filtering import async_setup_all_entity_ids_cache_invalidation
from .integration_linking import link_sub_integrations, unlink_sub_integrations
from .listeners import async_listen_once_tracked
@@ -90,10 +91,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
# spanned a restart would be a disable nobody remembers making.
entry.async_on_unload(await async_setup_timed_states(hass))
# Set up services
# Set up services. Unloading is registered first: setting up starts
# listening before it is done, and Home Assistant runs these callbacks
# when a setup fails or is cancelled too. Registered afterwards, a failed
# setup would leave the manager listening and registering actions for a
# Spook that never loaded.
services = SpookServiceManager(hass)
await services.async_setup()
entry.async_on_unload(services.async_on_unload)
await services.async_setup()
# Watching before anything can start a wait it has to observe. A repair
# can put a statistic on the clock the first time it looks, and on the
@@ -102,12 +107,36 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
# of what it is meant to be watching.
entry.async_on_unload(async_setup_abandoned_statistics_watching(hass))
# Loaded before any repair looks, because the first thing a repair does
# with what it finds is check whether somebody already said to leave it.
entry.async_on_unload(await async_setup_dismissals(hass))
# Who you gonna call? SpookRepairManager!
repairs = SpookRepairManager(hass)
# Starting the repairs takes a moment, and on a normal start that moment
# comes after this setup is long done. Spook can be disabled or reloaded
# in it, and the unload that runs then has not been told about repairs
# that are not there yet. They finished starting afterwards with nothing
# left to stop them.
unloaded = False
@callback
def _note_the_unload() -> None:
"""Remember Spook went, for repairs that were still on their way."""
nonlocal unloaded
unloaded = True
entry.async_on_unload(_note_the_unload)
async def _ghost_busters(_: Event | None = None) -> None:
"""Send them in, time for some ghost chasing."""
await repairs.async_setup()
if unloaded:
await repairs.async_on_unload()
return
entry.async_on_unload(repairs.async_on_unload)
if hass.state == CoreState.running: