Repository navigation
Detect unknown actions in template helpers - #1397
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 4 included reviews per hour; 1 remains after this review. 📝 WalkthroughWalkthroughTemplate helper repairs now inspect structured action configurations for unknown entity and service references. They distinguish disabled-only entity references, validate action options, update repair issues as services change, and document the resulting diagnostics. ChangesTemplate helper repairs
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to This change adds detection for unavailable actions in Template helpers and links the affected helper from repair notifications; no actionable merge-blocking risk remains beyond normal checks and review. Sequence Diagram(s)sequenceDiagram
participant HomeAssistantEvents
participant SpookRepair
participant async_find_services_in_sequence
participant RepairIssueRegistry
HomeAssistantEvents->>SpookRepair: trigger configuration, reload, or service changes
SpookRepair->>async_find_services_in_sequence: inspect normalized helper actions
async_find_services_in_sequence-->>SpookRepair: referenced services
SpookRepair->>RepairIssueRegistry: create or remove unknown-service issues
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Adds unknown-action detection to Template integration helpers.
Changes:
- Scans template-helper action sequences for unavailable services.
- Adds repair translations and regression tests.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
unknown_service_references.py |
Implements action-reference inspection. |
en.json |
Adds repair messaging. |
test_unknown_entity_references.py |
Tests button and switch actions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
Suppressed comments (1)
custom_components/spook/ectoplasms/template/repairs/unknown_service_references.py:51
- Template helper options are raw config, so a templated action such as
{"action": "{{ action_name }}"}remains a plain string. This adds that Jinja expression toservices, andasync_filter_known_servicesconsequently reports it as an unavailable action. Skipis_template_string(...)values when walking these raw sequences (and add a regression case), as the existing raw-config warning intests/test_entity_filtering.py:73-75requires.
services.update(async_find_services_in_sequence(option))
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1397 +/- ##
==========================================
+ Coverage 84.49% 84.85% +0.35%
==========================================
Files 152 153 +1
Lines 4419 4449 +30
Branches 564 567 +3
==========================================
+ Hits 3734 3775 +41
+ Misses 576 568 -8
+ Partials 109 106 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Two conflicts, both from frenck#1399 and frenck#1400 landing: - en.json keeps main's "Its configuration references" wording, with the Helpers link layered on top. - The tests move into test_unknown_service_references.py, one file per repair as the script ectoplasm already does. That is also what stops this conflict recurring, since both sides were appending to the same file.
async_find_services_in_sequence was written for validated script sequences and indexes keys that only exist after cv.SCRIPT_SCHEMA has run. This repair was the first caller handing it raw config entry options, and it raised on shapes the action editor writes every day: parallel shorthand KeyError: 'sequence' bare repeat KeyError: 'sequence' if without then KeyError: 'then' a step with an alias and nothing else ValueError The exception escaped async_inspect and repairs.py re-raises it, so one such helper meant every config entry after it went uninspected and the repair reported nothing at all, with a traceback on every trigger. Validating first fixes all of them, and turns parallel shorthand from fatal into a real detection. It also replaces two heuristics with a real answer: the isinstance() shape guard, and the is_template_string filter, since a templated action name validates into a Template and a Template is not a string, so the known-services filter drops it already. Also drop the entity registry subscription. Service availability does not track the entity registry, script entities appearing already fire EVENT_SERVICE_REGISTERED, and neither the script nor the automation service repair listens for it. And say "It references the following actions" rather than "Its actions reference the following actions", matching the script repair.
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
Suppressed comments (3)
custom_components/spook/ectoplasms/template/repairs/unknown_service_references.py:62
- This walker does not recurse into Home Assistant's valid
sequenceaction type, so a helper option such as[{"sequence": [{"action": "script.missing"}]}]validates successfully but yields no service and no repair. Extendasync_find_services_in_sequenceto handlecv.SCRIPT_ACTION_SEQUENCEviastep[CONF_SEQUENCE], and add this shape to the regression test.
services.update(async_find_services_in_sequence(sequence))
documentation/integrations/template.md:46
- Use the singular attributive noun “Feature” in this heading.
## Features requests, ideas, and support
custom_components/spook/translations/en.json:500
- “Crossed path” should use the idiom’s plural form, “crossed paths.”
"description": "Spook has found a ghost in your template helpers \ud83d\udc7b\n\nWhile floating around, Spook crossed path with the following template helper:\n\n[{helper}]({edit})\n\nIt references the following actions, which are unknown to Home Assistant:\n\n{services}\n\n\n\nThis often happens when an action provider was removed, or a script was renamed or deleted. To fix this error, reconfigure the template helper to use existing actions.\n\nSpook \ud83d\udc7b Your homie.",



Description
Motivation and Context
The existing Template repair only inspects Jinja template strings for unknown entities. It does not inspect Home Assistant action sequences stored in Template helper options, such as a Template Button's
pressoption.This fixes a missing script action (
script.something) that was referenced by one of my Template Button but was not reported by Spook.Related discussion
Discussion #1285 identified the companion problem of unknown entity references in UI-created Template helpers. That coverage was added in #1367. This PR complements it by detecting unavailable actions/services in Template helper action sequences, including
press,turn_on, andturn_off; action names templated at runtime are intentionally skipped.How has this been tested?
turn_on/turn_offactions, and a templated action name.myst build --html.Screenshots (if appropriate):
Types of changes
Checklist