208 files

This commit is contained in:
Home Assistant Version Control
2026-10-07 02:49:21 +00:00
parent a7107ecbe1
commit cfd0d40c8e
208 changed files with 5434 additions and 901 deletions
@@ -8,7 +8,10 @@ from homeassistant.components import automation
from homeassistant.helpers import area_registry as ar
from ....entity_filtering import async_filter_known_area_ids, async_get_all_area_ids
from ....reference_extraction import extract_targets_from_config
from ....reference_extraction import (
extract_targets_from_config,
only_in_disabled_steps,
)
from . import AbstractSpookAutomationReferencesRepair
if TYPE_CHECKING:
@@ -45,6 +48,10 @@ class SpookRepair(AbstractSpookAutomationReferencesRepair):
# references nested in some step types, like repeat sequences.
if raw_config := getattr(entity, "raw_config", None):
area_ids.update(extract_targets_from_config(raw_config).area_ids)
# A disabled step does nothing, so what only it names is left out.
area_ids -= only_in_disabled_steps(
raw_config, lambda found: extract_targets_from_config(found).area_ids
)
return async_filter_known_area_ids(
self.hass,
@@ -8,7 +8,10 @@ from homeassistant.components import automation
from homeassistant.helpers import device_registry as dr
from ....entity_filtering import async_filter_known_device_ids, async_get_all_device_ids
from ....reference_extraction import extract_targets_from_config
from ....reference_extraction import (
extract_targets_from_config,
only_in_disabled_steps,
)
from ....template_extraction import extract_device_ids_from_config
from . import AbstractSpookAutomationReferencesRepair
@@ -91,6 +94,14 @@ class SpookRepair(AbstractSpookAutomationReferencesRepair):
)
# Devices referenced via device_entities() in templates.
device_ids.update(extract_device_ids_from_config(entity.raw_config))
# A disabled step does nothing, so what only it names is left out.
device_ids -= only_in_disabled_steps(
entity.raw_config,
lambda found: (
extract_targets_from_config(found).device_ids
| extract_device_ids_from_config(found)
),
)
return async_filter_known_device_ids(
self.hass,
@@ -13,6 +13,7 @@ from ....action_extraction import (
async_extract_entities_from_value,
)
from ....entity_filtering import async_get_all_entity_ids, async_get_all_services
from ....reference_extraction import without_disabled_steps
from ....template_extraction import (
KNOWN_DOMAINS,
async_extract_entities_from_config,
@@ -291,6 +292,21 @@ class SpookRepair(AbstractSpookAutomationReferencesRepair):
)
self._known_services = async_get_all_services(self.hass)
async def _async_named_in(self, config: dict[str, Any]) -> set[str]:
"""Return the entities a configuration names, the way this repair reads it.
The same reading the report is built from, structure and templates
alike, so comparing it with and without the disabled steps leaves out
exactly what only those name.
"""
named = await extract_entities_from_automation_config(
self.hass, config, self._known_services
)
named |= await async_extract_entities_from_config(
self.hass, config, self._known_services
)
return named
async def _async_compute_unknown_references(self, entity: Any) -> set[str]:
"""Return unknown entity IDs referenced by ``entity`` (incl. templates)."""
all_entities = set(entity.referenced_entities)
@@ -314,6 +330,15 @@ class SpookRepair(AbstractSpookAutomationReferencesRepair):
)
)
# Home Assistant's own list includes disabled steps, triggers and
# conditions too. Something parked that way does nothing, so what only
# it names is left out of the report: whatever this repair finds in
# the configuration, and no longer finds once those are pruned.
if isinstance(raw_config := getattr(entity, "raw_config", None), dict):
named = await self._async_named_in(raw_config)
still_named = await self._async_named_in(without_disabled_steps(raw_config))
all_entities -= named - still_named
return await async_filter_known_entity_ids_with_templates(
self.hass,
entity_ids=all_entities,
@@ -8,7 +8,10 @@ from homeassistant.components import automation
from homeassistant.helpers import floor_registry as fr
from ....entity_filtering import async_filter_known_floor_ids, async_get_all_floor_ids
from ....reference_extraction import extract_targets_from_config
from ....reference_extraction import (
extract_targets_from_config,
only_in_disabled_steps,
)
from . import AbstractSpookAutomationReferencesRepair
if TYPE_CHECKING:
@@ -44,6 +47,10 @@ class SpookRepair(AbstractSpookAutomationReferencesRepair):
# references nested in some step types, like repeat sequences.
if raw_config := getattr(entity, "raw_config", None):
floor_ids.update(extract_targets_from_config(raw_config).floor_ids)
# A disabled step does nothing, so what only it names is left out.
floor_ids -= only_in_disabled_steps(
raw_config, lambda found: extract_targets_from_config(found).floor_ids
)
return async_filter_known_floor_ids(
self.hass,
@@ -8,7 +8,10 @@ from homeassistant.components import automation
from homeassistant.helpers import label_registry as lr
from ....entity_filtering import async_filter_known_label_ids, async_get_all_label_ids
from ....reference_extraction import extract_targets_from_config
from ....reference_extraction import (
extract_targets_from_config,
only_in_disabled_steps,
)
from . import AbstractSpookAutomationReferencesRepair
if TYPE_CHECKING:
@@ -44,6 +47,10 @@ class SpookRepair(AbstractSpookAutomationReferencesRepair):
# references nested in some step types, like repeat sequences.
if raw_config := getattr(entity, "raw_config", None):
label_ids.update(extract_targets_from_config(raw_config).label_ids)
# A disabled step does nothing, so what only it names is left out.
label_ids -= only_in_disabled_steps(
raw_config, lambda found: extract_targets_from_config(found).label_ids
)
return async_filter_known_label_ids(
self.hass,