429 files
This commit is contained in:
Binary file not shown.
@@ -2,16 +2,20 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from homeassistant.components import script
|
||||
from homeassistant.helpers import area_registry as ar
|
||||
from homeassistant.helpers.entity_component import DATA_INSTANCES, EntityComponent
|
||||
|
||||
from ....const import LOGGER
|
||||
from ....entity_filtering import async_filter_known_area_ids, async_get_all_area_ids
|
||||
from ....repairs import AbstractSpookRepair
|
||||
from ....reference_extraction import extract_targets_from_config
|
||||
from ....repairs import AbstractSpookEntityComponentUnknownReferencesRepair
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Any
|
||||
|
||||
|
||||
class SpookRepair(AbstractSpookRepair):
|
||||
class SpookRepair(AbstractSpookEntityComponentUnknownReferencesRepair):
|
||||
"""Spook repair tries to find unknown referenced areas in scripts."""
|
||||
|
||||
domain = script.DOMAIN
|
||||
@@ -19,44 +23,28 @@ class SpookRepair(AbstractSpookRepair):
|
||||
inspect_events = {ar.EVENT_AREA_REGISTRY_UPDATED}
|
||||
inspect_on_reload = True
|
||||
|
||||
automatically_clean_up_issues = True
|
||||
unavailable_entity_class = script.UnavailableScriptEntity
|
||||
entity_label = "script"
|
||||
reference_label = "areas"
|
||||
edit_url_pattern = "/config/script/edit/{unique_id}"
|
||||
|
||||
async def async_inspect(self) -> None:
|
||||
"""Trigger a inspection."""
|
||||
if self.domain not in self.hass.data[DATA_INSTANCES]:
|
||||
return
|
||||
_known_area_ids: set[str]
|
||||
|
||||
entity_component: EntityComponent[script.ScriptEntity] = self.hass.data[
|
||||
DATA_INSTANCES
|
||||
][self.domain]
|
||||
async def _async_setup_inspection(self) -> None:
|
||||
"""Cache known area IDs for this inspection cycle."""
|
||||
self._known_area_ids = async_get_all_area_ids(self.hass)
|
||||
|
||||
LOGGER.debug("Spook is inspecting: %s", self.repair)
|
||||
async def _async_compute_unknown_references(self, entity: Any) -> set[str]:
|
||||
"""Return unknown area IDs referenced by ``entity``."""
|
||||
area_ids = set(entity.script.referenced_areas)
|
||||
|
||||
known_area_ids = async_get_all_area_ids(self.hass)
|
||||
# Also walk the raw configuration; the built-in extraction misses
|
||||
# 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)
|
||||
|
||||
for entity in entity_component.entities:
|
||||
self.possible_issue_ids.add(entity.entity_id)
|
||||
if not isinstance(entity, script.UnavailableScriptEntity) and (
|
||||
unknown_areas := async_filter_known_area_ids(
|
||||
self.hass,
|
||||
area_ids=entity.script.referenced_areas,
|
||||
known_area_ids=known_area_ids,
|
||||
)
|
||||
):
|
||||
self.async_create_issue(
|
||||
issue_id=entity.entity_id,
|
||||
translation_placeholders={
|
||||
"areas": "\n".join(f"- `{area}`" for area in unknown_areas),
|
||||
"script": entity.name,
|
||||
"edit": f"/config/script/edit/{entity.unique_id}",
|
||||
"entity_id": entity.entity_id,
|
||||
},
|
||||
)
|
||||
LOGGER.debug(
|
||||
(
|
||||
"Spook found unknown areas in %s "
|
||||
"and created an issue for it; Areas: %s"
|
||||
),
|
||||
entity.entity_id,
|
||||
", ".join(unknown_areas),
|
||||
)
|
||||
return async_filter_known_area_ids(
|
||||
self.hass,
|
||||
area_ids=area_ids,
|
||||
known_area_ids=self._known_area_ids,
|
||||
)
|
||||
|
||||
@@ -2,16 +2,21 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from homeassistant.components import script
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.entity_component import DATA_INSTANCES, EntityComponent
|
||||
|
||||
from ....const import LOGGER
|
||||
from ....entity_filtering import async_filter_known_device_ids, async_get_all_device_ids
|
||||
from ....repairs import AbstractSpookRepair
|
||||
from ....reference_extraction import extract_targets_from_config
|
||||
from ....repairs import AbstractSpookEntityComponentUnknownReferencesRepair
|
||||
from ....template_extraction import extract_device_ids_from_config
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Any
|
||||
|
||||
|
||||
class SpookRepair(AbstractSpookRepair):
|
||||
class SpookRepair(AbstractSpookEntityComponentUnknownReferencesRepair):
|
||||
"""Spook repair tries to find unknown referenced devices in scripts."""
|
||||
|
||||
domain = script.DOMAIN
|
||||
@@ -20,45 +25,30 @@ class SpookRepair(AbstractSpookRepair):
|
||||
inspect_config_entry_changed = True
|
||||
inspect_on_reload = True
|
||||
|
||||
automatically_clean_up_issues = True
|
||||
unavailable_entity_class = script.UnavailableScriptEntity
|
||||
entity_label = "script"
|
||||
reference_label = "devices"
|
||||
edit_url_pattern = "/config/script/edit/{unique_id}"
|
||||
|
||||
async def async_inspect(self) -> None:
|
||||
"""Trigger a inspection."""
|
||||
if self.domain not in self.hass.data[DATA_INSTANCES]:
|
||||
return
|
||||
_known_device_ids: set[str]
|
||||
|
||||
entity_component: EntityComponent[script.ScriptEntity] = self.hass.data[
|
||||
DATA_INSTANCES
|
||||
][self.domain]
|
||||
async def _async_setup_inspection(self) -> None:
|
||||
"""Cache known device IDs for this inspection cycle."""
|
||||
self._known_device_ids = async_get_all_device_ids(self.hass)
|
||||
|
||||
known_device_ids = async_get_all_device_ids(self.hass)
|
||||
async def _async_compute_unknown_references(self, entity: Any) -> set[str]:
|
||||
"""Return unknown device IDs referenced by ``entity``."""
|
||||
device_ids = set(entity.script.referenced_devices)
|
||||
|
||||
LOGGER.debug("Spook is inspecting: %s", self.repair)
|
||||
for entity in entity_component.entities:
|
||||
self.possible_issue_ids.add(entity.entity_id)
|
||||
if not isinstance(entity, script.UnavailableScriptEntity) and (
|
||||
unknown_devices := async_filter_known_device_ids(
|
||||
self.hass,
|
||||
device_ids=entity.script.referenced_devices,
|
||||
known_device_ids=known_device_ids,
|
||||
)
|
||||
):
|
||||
self.async_create_issue(
|
||||
issue_id=entity.entity_id,
|
||||
translation_placeholders={
|
||||
"devices": "\n".join(
|
||||
f"- `{device}`" for device in unknown_devices
|
||||
),
|
||||
"script": entity.name,
|
||||
"edit": f"/config/script/edit/{entity.unique_id}",
|
||||
"entity_id": entity.entity_id,
|
||||
},
|
||||
)
|
||||
LOGGER.debug(
|
||||
(
|
||||
"Spook found unknown devices in %s "
|
||||
"and created an issue for it; Devices: %s",
|
||||
),
|
||||
entity.entity_id,
|
||||
", ".join(unknown_devices),
|
||||
)
|
||||
# Also walk the raw configuration; the built-in extraction misses
|
||||
# references nested in some step types, like repeat sequences.
|
||||
if raw_config := getattr(entity, "raw_config", None):
|
||||
device_ids.update(extract_targets_from_config(raw_config).device_ids)
|
||||
# Devices referenced via device_entities() in templates.
|
||||
device_ids.update(extract_device_ids_from_config(raw_config))
|
||||
|
||||
return async_filter_known_device_ids(
|
||||
self.hass,
|
||||
device_ids=device_ids,
|
||||
known_device_ids=self._known_device_ids,
|
||||
)
|
||||
|
||||
@@ -7,14 +7,13 @@ from typing import TYPE_CHECKING, Any
|
||||
from homeassistant.components import script
|
||||
from homeassistant.const import EVENT_COMPONENT_LOADED
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.entity_component import DATA_INSTANCES, EntityComponent
|
||||
|
||||
from ....entity_filtering import (
|
||||
from ....entity_filtering import async_get_all_entity_ids
|
||||
from ....repairs import AbstractSpookEntityComponentUnknownReferencesRepair
|
||||
from ....template_extraction import (
|
||||
async_extract_entities_from_config,
|
||||
async_filter_known_entity_ids_with_templates,
|
||||
async_get_all_entity_ids,
|
||||
)
|
||||
from ....repairs import AbstractSpookRepair
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from homeassistant.core import HomeAssistant
|
||||
@@ -86,7 +85,7 @@ async def extract_template_entities_from_script_entity(
|
||||
return await async_extract_entities_from_config(hass, config)
|
||||
|
||||
|
||||
class SpookRepair(AbstractSpookRepair):
|
||||
class SpookRepair(AbstractSpookEntityComponentUnknownReferencesRepair):
|
||||
"""Spook repair tries to find unknown referenced entity in scripts."""
|
||||
|
||||
domain = script.DOMAIN
|
||||
@@ -98,7 +97,13 @@ class SpookRepair(AbstractSpookRepair):
|
||||
inspect_config_entry_changed = True
|
||||
inspect_on_reload = True
|
||||
|
||||
automatically_clean_up_issues = True
|
||||
unavailable_entity_class = script.UnavailableScriptEntity
|
||||
entity_label = "script"
|
||||
reference_label = "entities"
|
||||
references_are_entities = True
|
||||
edit_url_pattern = "/config/script/edit/{unique_id}"
|
||||
|
||||
_known_entity_ids: set[str]
|
||||
|
||||
def _get_blueprint_trigger_entities(self, entity: script.ScriptEntity) -> set[str]:
|
||||
"""Extract entity references from blueprint trigger inputs."""
|
||||
@@ -128,49 +133,27 @@ class SpookRepair(AbstractSpookRepair):
|
||||
|
||||
return entities
|
||||
|
||||
async def async_inspect(self) -> None:
|
||||
"""Trigger a inspection."""
|
||||
if self.domain not in self.hass.data[DATA_INSTANCES]:
|
||||
return
|
||||
async def _async_setup_inspection(self) -> None:
|
||||
"""Cache known entity IDs (including ALL/NONE) for this inspection cycle."""
|
||||
self._known_entity_ids = async_get_all_entity_ids(
|
||||
self.hass, include_all_none=True
|
||||
)
|
||||
|
||||
entity_component: EntityComponent[script.ScriptEntity] = self.hass.data[
|
||||
DATA_INSTANCES
|
||||
][self.domain]
|
||||
async def _async_compute_unknown_references(self, entity: Any) -> set[str]:
|
||||
"""Return unknown entity IDs referenced by ``entity`` (incl. templates)."""
|
||||
# Get all referenced entities from the script
|
||||
all_entities = extract_referenced_entities_from_script(entity)
|
||||
|
||||
known_entity_ids = async_get_all_entity_ids(self.hass, include_all_none=True)
|
||||
# Check for blueprint trigger inputs
|
||||
all_entities.update(self._get_blueprint_trigger_entities(entity))
|
||||
|
||||
for entity in entity_component.entities:
|
||||
self.possible_issue_ids.add(entity.entity_id)
|
||||
if isinstance(entity, script.UnavailableScriptEntity):
|
||||
continue
|
||||
# Extract entities from Template objects within the script entity
|
||||
all_entities.update(
|
||||
await extract_template_entities_from_script_entity(self.hass, entity)
|
||||
)
|
||||
|
||||
# Get all referenced entities from the script
|
||||
all_entities = extract_referenced_entities_from_script(entity)
|
||||
|
||||
# Check for blueprint trigger inputs
|
||||
blueprint_entities = self._get_blueprint_trigger_entities(entity)
|
||||
all_entities.update(blueprint_entities)
|
||||
|
||||
# Extract entities from Template objects within the script entity
|
||||
template_entities = await extract_template_entities_from_script_entity(
|
||||
self.hass, entity
|
||||
)
|
||||
all_entities.update(template_entities)
|
||||
|
||||
# Check for unknown entities
|
||||
if unknown_entities := await async_filter_known_entity_ids_with_templates(
|
||||
self.hass,
|
||||
entity_ids=all_entities,
|
||||
known_entity_ids=known_entity_ids,
|
||||
):
|
||||
self.async_create_issue(
|
||||
issue_id=entity.entity_id,
|
||||
translation_placeholders={
|
||||
"entities": "\n".join(
|
||||
f"- `{entity_id}`" for entity_id in unknown_entities
|
||||
),
|
||||
"script": entity.name,
|
||||
"edit": f"/config/script/edit/{entity.unique_id}",
|
||||
"entity_id": entity.entity_id,
|
||||
},
|
||||
)
|
||||
return await async_filter_known_entity_ids_with_templates(
|
||||
self.hass,
|
||||
entity_ids=all_entities,
|
||||
known_entity_ids=self._known_entity_ids,
|
||||
)
|
||||
|
||||
@@ -2,16 +2,20 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from homeassistant.components import script
|
||||
from homeassistant.helpers import floor_registry as fr
|
||||
from homeassistant.helpers.entity_component import DATA_INSTANCES, EntityComponent
|
||||
|
||||
from ....const import LOGGER
|
||||
from ....entity_filtering import async_filter_known_floor_ids, async_get_all_floor_ids
|
||||
from ....repairs import AbstractSpookRepair
|
||||
from ....reference_extraction import extract_targets_from_config
|
||||
from ....repairs import AbstractSpookEntityComponentUnknownReferencesRepair
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Any
|
||||
|
||||
|
||||
class SpookRepair(AbstractSpookRepair):
|
||||
class SpookRepair(AbstractSpookEntityComponentUnknownReferencesRepair):
|
||||
"""Spook repair tries to find unknown referenced floors in scripts."""
|
||||
|
||||
domain = script.DOMAIN
|
||||
@@ -19,43 +23,28 @@ class SpookRepair(AbstractSpookRepair):
|
||||
inspect_events = {fr.EVENT_FLOOR_REGISTRY_UPDATED}
|
||||
inspect_on_reload = True
|
||||
|
||||
automatically_clean_up_issues = True
|
||||
unavailable_entity_class = script.UnavailableScriptEntity
|
||||
entity_label = "script"
|
||||
reference_label = "floors"
|
||||
edit_url_pattern = "/config/script/edit/{unique_id}"
|
||||
|
||||
async def async_inspect(self) -> None:
|
||||
"""Trigger a inspection."""
|
||||
if self.domain not in self.hass.data[DATA_INSTANCES]:
|
||||
return
|
||||
_known_floor_ids: set[str]
|
||||
|
||||
entity_component: EntityComponent[script.ScriptEntity] = self.hass.data[
|
||||
DATA_INSTANCES
|
||||
][self.domain]
|
||||
async def _async_setup_inspection(self) -> None:
|
||||
"""Cache known floor IDs for this inspection cycle."""
|
||||
self._known_floor_ids = async_get_all_floor_ids(self.hass)
|
||||
|
||||
known_floor_ids = async_get_all_floor_ids(self.hass)
|
||||
async def _async_compute_unknown_references(self, entity: Any) -> set[str]:
|
||||
"""Return unknown floor IDs referenced by ``entity``."""
|
||||
floor_ids = set(entity.script.referenced_floors)
|
||||
|
||||
LOGGER.debug("Spook is inspecting: %s", self.repair)
|
||||
for entity in entity_component.entities:
|
||||
self.possible_issue_ids.add(entity.entity_id)
|
||||
if not isinstance(entity, script.UnavailableScriptEntity) and (
|
||||
unknown_floors := async_filter_known_floor_ids(
|
||||
self.hass,
|
||||
floor_ids=entity.script.referenced_floors,
|
||||
known_floor_ids=known_floor_ids,
|
||||
)
|
||||
):
|
||||
self.async_create_issue(
|
||||
issue_id=entity.entity_id,
|
||||
translation_placeholders={
|
||||
"floors": "\n".join(f"- `{floor}`" for floor in unknown_floors),
|
||||
"script": entity.name,
|
||||
"edit": f"/config/script/edit/{entity.unique_id}",
|
||||
"entity_id": entity.entity_id,
|
||||
},
|
||||
)
|
||||
LOGGER.debug(
|
||||
(
|
||||
"Spook found unknown floors in %s "
|
||||
"and created an issue for it; Floors: %s",
|
||||
),
|
||||
entity.entity_id,
|
||||
", ".join(unknown_floors),
|
||||
)
|
||||
# Also walk the raw configuration; the built-in extraction misses
|
||||
# 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)
|
||||
|
||||
return async_filter_known_floor_ids(
|
||||
self.hass,
|
||||
floor_ids=floor_ids,
|
||||
known_floor_ids=self._known_floor_ids,
|
||||
)
|
||||
|
||||
@@ -2,16 +2,20 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from homeassistant.components import script
|
||||
from homeassistant.helpers import label_registry as lr
|
||||
from homeassistant.helpers.entity_component import DATA_INSTANCES, EntityComponent
|
||||
|
||||
from ....const import LOGGER
|
||||
from ....entity_filtering import async_filter_known_label_ids, async_get_all_label_ids
|
||||
from ....repairs import AbstractSpookRepair
|
||||
from ....reference_extraction import extract_targets_from_config
|
||||
from ....repairs import AbstractSpookEntityComponentUnknownReferencesRepair
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Any
|
||||
|
||||
|
||||
class SpookRepair(AbstractSpookRepair):
|
||||
class SpookRepair(AbstractSpookEntityComponentUnknownReferencesRepair):
|
||||
"""Spook repair tries to find unknown referenced labels in scripts."""
|
||||
|
||||
domain = script.DOMAIN
|
||||
@@ -19,43 +23,28 @@ class SpookRepair(AbstractSpookRepair):
|
||||
inspect_events = {lr.EVENT_LABEL_REGISTRY_UPDATED}
|
||||
inspect_on_reload = True
|
||||
|
||||
automatically_clean_up_issues = True
|
||||
unavailable_entity_class = script.UnavailableScriptEntity
|
||||
entity_label = "script"
|
||||
reference_label = "labels"
|
||||
edit_url_pattern = "/config/script/edit/{unique_id}"
|
||||
|
||||
async def async_inspect(self) -> None:
|
||||
"""Trigger a inspection."""
|
||||
if self.domain not in self.hass.data[DATA_INSTANCES]:
|
||||
return
|
||||
_known_label_ids: set[str]
|
||||
|
||||
entity_component: EntityComponent[script.ScriptEntity] = self.hass.data[
|
||||
DATA_INSTANCES
|
||||
][self.domain]
|
||||
async def _async_setup_inspection(self) -> None:
|
||||
"""Cache known label IDs for this inspection cycle."""
|
||||
self._known_label_ids = async_get_all_label_ids(self.hass)
|
||||
|
||||
known_label_ids = async_get_all_label_ids(self.hass)
|
||||
async def _async_compute_unknown_references(self, entity: Any) -> set[str]:
|
||||
"""Return unknown label IDs referenced by ``entity``."""
|
||||
label_ids = set(entity.script.referenced_labels)
|
||||
|
||||
LOGGER.debug("Spook is inspecting: %s", self.repair)
|
||||
for entity in entity_component.entities:
|
||||
self.possible_issue_ids.add(entity.entity_id)
|
||||
if not isinstance(entity, script.UnavailableScriptEntity) and (
|
||||
unknown_labels := async_filter_known_label_ids(
|
||||
self.hass,
|
||||
label_ids=entity.script.referenced_labels,
|
||||
known_label_ids=known_label_ids,
|
||||
)
|
||||
):
|
||||
self.async_create_issue(
|
||||
issue_id=entity.entity_id,
|
||||
translation_placeholders={
|
||||
"labels": "\n".join(f"- `{label}`" for label in unknown_labels),
|
||||
"script": entity.name,
|
||||
"edit": f"/config/script/edit/{entity.unique_id}",
|
||||
"entity_id": entity.entity_id,
|
||||
},
|
||||
)
|
||||
LOGGER.debug(
|
||||
(
|
||||
"Spook found unknown labels in %s "
|
||||
"and created an issue for it; Labels: %s",
|
||||
),
|
||||
entity.entity_id,
|
||||
", ".join(unknown_labels),
|
||||
)
|
||||
# Also walk the raw configuration; the built-in extraction misses
|
||||
# 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)
|
||||
|
||||
return async_filter_known_label_ids(
|
||||
self.hass,
|
||||
label_ids=label_ids,
|
||||
known_label_ids=self._known_label_ids,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user