Repository navigation
Ignore entity ID prefixes in templates - #1306
Conversation
|
Warning Review limit reached
More reviews will be available in 10 minutes and 5 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughA new helper predicate ChangesString-method argument false positive fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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.
🧹 Nitpick comments (1)
tests/ectoplasms/automation/repairs/test_unknown_entity_references.py (1)
69-80: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick winAdd a companion
endswithtest for symmetry with the new predicate.The implementation now explicitly handles both
startswithandendswith, but only the prefix path is covered here. A suffix-case test will lock the full contract and prevent regressions.Suggested test addition
+async def test_value_template_ignores_entity_id_suffix_string_match( + hass: HomeAssistant, +) -> None: + """String suffix checks are not complete entity references.""" + template = ( + "{% for entity in states.binary_sensor if " + "entity.entity_id.endswith('.proxmox') %}" + "{{ entity.state }}" + "{% endfor %}" + ) + + assert await extract_entities_from_value(hass, template) == set()🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/ectoplasms/automation/repairs/test_unknown_entity_references.py` around lines 69 - 80, Add a new async test function that mirrors test_value_template_ignores_entity_id_prefix_string_match but uses the endswith method instead of startswith to verify that string suffix checks are also not recognized as complete entity references and return an empty set. This ensures the endswith path is tested symmetrically with the prefix test and prevents regressions in the implementation that handles both startswith and endswith predicates.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/ectoplasms/automation/repairs/test_unknown_entity_references.py`:
- Around line 69-80: Add a new async test function that mirrors
test_value_template_ignores_entity_id_prefix_string_match but uses the endswith
method instead of startswith to verify that string suffix checks are also not
recognized as complete entity references and return an empty set. This ensures
the endswith path is tested symmetrically with the prefix test and prevents
regressions in the implementation that handles both startswith and endswith
predicates.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: ae6efcb8-4b6c-4d98-b299-b2e2b102d358
📒 Files selected for processing (2)
custom_components/spook/entity_filtering.pytests/ectoplasms/automation/repairs/test_unknown_entity_references.py
There was a problem hiding this comment.
Pull request overview
This PR addresses false-positive “Unknown entities used” repairs by teaching Spook’s template regex extractor to ignore entity-like strings when they are used as prefix/suffix arguments in Jinja string checks (e.g., startswith()), rather than as concrete entity references.
Changes:
- Add regex-side filtering to skip entity-like literals used as arguments to
.startswith()/.endswith()in templates. - Add a regression test ensuring a
startswith('binary_sensor.proxmox')prefix check does not yield an entity reference.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
custom_components/spook/entity_filtering.py |
Adds _is_string_method_argument_match and integrates it into template entity extraction to avoid false positives from prefix/suffix checks. |
tests/ectoplasms/automation/repairs/test_unknown_entity_references.py |
Adds a regression test for templates using entity.entity_id.startswith(...) to ensure no entities are extracted. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|



Summary
Fixes #1090 by ignoring entity-like strings that are used as string-prefix or string-suffix checks in Jinja templates.
A template such as
entity.entity_id.startswith('binary_sensor.proxmox')usesbinary_sensor.proxmoxas a prefix, not as a concrete entity ID. Spook now keeps that out of the unknown entity repair while still detecting actual entity references.Validation
uv run pytest tests/ectoplasms/automation/repairs/test_unknown_entity_references.py -quv run ruff format --check custom_components/spook/entity_filtering.py tests/ectoplasms/automation/repairs/test_unknown_entity_references.pyuv run ruff check --output-format=github custom_components/spook/entity_filtering.py tests/ectoplasms/automation/repairs/test_unknown_entity_references.pyuv run --with pre-commit pre-commit run pylint --files custom_components/spook/entity_filtering.py tests/ectoplasms/automation/repairs/test_unknown_entity_references.py