Repository navigation
Use the generic walker in the Lovelace repair - #1364
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe Lovelace unknown-entity-references repair is refactored to extract entities using a shared ChangesShared Dashboard Extraction Refactor
Estimated code review effort: 2 (Simple) | ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1364 +/- ##
==========================================
- Coverage 81.60% 81.36% -0.25%
==========================================
Files 132 132
Lines 3730 3585 -145
Branches 509 447 -62
==========================================
- Hits 3044 2917 -127
+ Misses 586 581 -5
+ Partials 100 87 -13 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR replaces the Lovelace unknown_entity_references repair's ~250 lines of hand-rolled, per-card entity-extraction methods with the generic extract_entities_from_dashboard_node walker (introduced in #1363), invoked once per view. The repair keeps its view-path bookkeeping (each entity maps to the first view it appears in, used for the issue's edit link), and comma-splitting now happens inside the walker via split_comma_separated_entity_ids. This fits Spook's broader pattern of centralizing extraction logic and relying on async_filter_known_entity_ids for downstream validation, and it also lets references buried in custom cards be discovered without per-card maintenance.
Changes:
- Swapped the per-card/badge/element/section/action extraction methods for a single call to the generic dashboard walker, keyed to view paths via
setdefault. - Updated imports (dropped the now-unused
split_comma_separated_entity_ids, addedextract_entities_from_dashboard_node). - Removed the card/badge/element unit tests and added a custom-card regression test; also removed the two state-only entity event-recheck tests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| custom_components/spook/ectoplasms/lovelace/repairs/unknown_entity_references.py | Replaces per-card extraction helpers with the generic walker while preserving per-view path bookkeeping. |
| tests/ectoplasms/lovelace/repairs/test_unknown_entity_references.py | Drops card/badge/element and state-only tests; adds a custom-card regression test and keeps view-path/issue tests. |
Notes:
- The generic walker's behavioral parity (badges, cards, sections, action targets/service_data, visibility conditions, chips, nested elements, comma-splitting) is preserved through recursion plus recognized keys, and is well-covered by
tests/test_dashboard_extraction.py. - The two removed state-only entity event tests cover behavior in
async_activatethat this PR does not change and that remains present, so that lovelace-specific event wiring is now untested (the parallel automation-repair tests are still kept).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| assert calls == 0 | ||
|
|
||
| await repair.async_deactivate() | ||
| assert _extract(repair, config) == {"sensor.custom": "home"} |
|
|
||
| from homeassistant.const import EVENT_STATE_CHANGED | ||
| from homeassistant.core import State | ||
|
|



Description
Replaces the Lovelace unknown entity references repair's ten hand-rolled per-card extraction methods with the generic
extract_entities_from_dashboard_nodewalker from #1363, called once per view. The repair keeps its view-path bookkeeping (each entity is mapped to the first view it appears in, for the issue's edit link) and its comma-splitting, but the extraction is now generic.Net effect: the repair drops ~250 lines, standard card behavior is unchanged, and references buried in custom cards or new built-in card shapes are now found without per-card maintenance.
The 21 card/badge/element tests that exercised the now-deleted private methods are removed; their behavioral coverage lives in
tests/test_dashboard_extraction.py(added with the walker). The repair's own view-path tests and issue-message test are kept, and a regression test is added proving a reference inside acustom:card structure is now surfaced.Motivation and Context
A custom card burying an
entitykey was invisible to the old walker, and every new built-in card shape needed a code change. One generic walk fixes both, and is far less code.How has this been tested?
The kept view-path tests confirm the repair's bookkeeping is unchanged; the new custom-card test confirms the coverage improvement; the walker itself is covered by
tests/test_dashboard_extraction.py. Full suite passes (571 tests), ruff, pylint (10.00/10), and all prek hooks pass.Screenshots (if appropriate):
Types of changes
Checklist