Repository navigation
Detect unknown actions in template helpers #1397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
frenck
merged 7 commits into
frenck:main
from
cnotin:agent/template-helper-unknown-actions
Aug 20, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1ed35bf
Detect unknown actions in template helpers
cnotin f4343af
Link template helper repairs to Helpers page
cnotin 1cac1be
Skip templated template helper actions
cnotin e292ef3
Document template helper repairs
cnotin 8c00b79
Merge branch 'main' into agent/template-helper-unknown-actions
frenck a0724c2
Merge branch 'main' into agent/template-helper-unknown-actions
frenck 35c6044
Validate template helper options before walking them for actions
frenck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
custom_components/spook/ectoplasms/template/repairs/unknown_service_references.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| """Spook - Your homie.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import voluptuous as vol | ||
|
|
||
| from homeassistant.const import ( | ||
| EVENT_COMPONENT_LOADED, | ||
| EVENT_SERVICE_REGISTERED, | ||
| EVENT_SERVICE_REMOVED, | ||
| ) | ||
| from homeassistant.helpers import config_validation as cv | ||
|
|
||
| from ....const import LOGGER | ||
| from ....entity_filtering import ( | ||
| async_filter_known_services, | ||
| async_find_services_in_sequence, | ||
| async_get_all_services, | ||
| ) | ||
| from ....repairs import AbstractSpookRepair | ||
|
|
||
|
|
||
| class SpookRepair(AbstractSpookRepair): | ||
| """Spook repair finds unknown actions referenced in template helpers.""" | ||
|
|
||
| domain = "template" | ||
| repair = "template_unknown_service_references" | ||
| inspect_events = { | ||
| EVENT_COMPONENT_LOADED, | ||
| EVENT_SERVICE_REGISTERED, | ||
| EVENT_SERVICE_REMOVED, | ||
| } | ||
| inspect_config_entry_changed = "template" | ||
| inspect_on_reload = "template" | ||
| automatically_clean_up_issues = True | ||
|
|
||
| async def async_inspect(self) -> None: | ||
| """Inspect template helper actions for unavailable services.""" | ||
| LOGGER.debug("Spook is inspecting: %s", self.repair) | ||
|
|
||
| known_services = async_get_all_services(self.hass) | ||
|
|
||
| for entry in self.hass.config_entries.async_entries(self.domain): | ||
| self.possible_issue_ids.add(entry.entry_id) | ||
|
|
||
| # Which options hold actions grows with every new template helper | ||
| # type, so ask Home Assistant instead of keeping a list of keys. | ||
| # | ||
| # Validating is not just a shape check. The walker reads keys that | ||
| # only exist after validation, so raw options make it raise on | ||
| # shapes the action editor writes every day, a `parallel` block | ||
| # among them. Validation normalizes those, and turns a templated | ||
| # action name into a Template, which is not a string and so falls | ||
| # out of the known-services filter on its own. | ||
| services = set() | ||
| for option in entry.options.values(): | ||
| try: | ||
| sequence = cv.SCRIPT_SCHEMA(option) | ||
| except vol.Invalid: | ||
| continue | ||
|
|
||
| services.update(async_find_services_in_sequence(sequence)) | ||
|
|
||
| unknown_services = async_filter_known_services( | ||
| self.hass, | ||
| services=services, | ||
| known_services=known_services, | ||
| ) | ||
| if not unknown_services: | ||
| continue | ||
|
|
||
| self.async_create_issue( | ||
| issue_id=entry.entry_id, | ||
| translation_placeholders={ | ||
| "helper": entry.title, | ||
| "edit": "/config/helpers", | ||
| "services": "\n".join( | ||
| f"- `{service}`" for service in sorted(unknown_services) | ||
| ), | ||
| }, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| --- | ||
| subject: Enhanced integrations | ||
| title: Template helpers | ||
| subtitle: Keep template helpers free of ghosts. 👻 | ||
| description: Spook inspects Template helpers and raises repair issues for references to unavailable entities and actions. | ||
| date: 2026-08-03T00:00:00+02:00 | ||
| --- | ||
|
|
||
| The [Template integration](https://www.home-assistant.io/integrations/template/) | ||
| lets you create helpers whose values and actions are based on templates. Spook | ||
| inspects Template helpers created in the Home Assistant user interface and | ||
| raises repair issues when it finds references that are no longer available. | ||
|
|
||
| ## Devices & entities | ||
|
|
||
| Spook does not provide any new devices or entities for this integration. | ||
|
|
||
| ## Actions | ||
|
|
||
| Spook does not provide action enhancements for this integration. | ||
|
|
||
| ## Repairs | ||
|
|
||
| While Spook is floating around in your Home Assistant instance, it raises a | ||
| repair issue when it finds something that is not right. | ||
|
|
||
| ### Unknown referenced entities | ||
|
|
||
| Spook inspects templates in Template helpers for entity IDs that do not exist. | ||
| The repair issue lists the helper and the unavailable entity IDs. To resolve the | ||
| issue, open the linked helper, update the reference to an existing entity, or | ||
| remove it. Spook automatically removes the repair issue once it is fixed. | ||
|
|
||
| ### Unknown referenced actions | ||
|
|
||
| Spook inspects action sequences configured in Template helpers, such as the | ||
| `press` action of a Template Button or the `turn_on` and `turn_off` actions of | ||
| a Template Switch. If an action is unavailable, the repair issue lists the | ||
| helper and the unavailable action. | ||
|
|
||
| To resolve the issue, open the linked helper, update the action to one provided | ||
| by Home Assistant, or restore the integration or script that provided it. | ||
| Templated action names are ignored because their value is determined at runtime. | ||
| Spook automatically removes the repair issue once it is fixed. | ||
|
|
||
| ## Features requests, ideas, and support | ||
|
|
||
| If you have an idea for a new action, entity, or repair detection, [let us know | ||
| in the discussion forums](https://github.com/frenck/spook/discussions). | ||
|
|
||
| Are you stuck? See the [](../support) page for where to get help. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.