Repository navigation
Offer to clean up unknown members in groups - #1383
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 (6)
✅ Files skipped from review due to trivial changes (2)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughAdds a repair flow for groups with unknown members, updates the repair issue payload to carry described entities, revises the related translations, and adds tests for the inspection and fix-flow behavior. ChangesGroup Unknown Members Repair Flow
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested labels: 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❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1383 +/- ##
==========================================
+ Coverage 83.42% 83.67% +0.24%
==========================================
Files 146 146
Lines 4182 4203 +21
Branches 535 538 +3
==========================================
+ Hits 3489 3517 +28
+ Misses 593 583 -10
- Partials 100 103 +3 ☔ 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 turns the existing group_unknown_members repair from an informational notice into an actionable one. Previously the repair only detected groups (UI-managed light/switch/generic groups and YAML groups) that still referenced members that no longer exist. Now it presents a remove/manage/ignore menu built on the shared _RemoveOrIgnoreFixFlow base, allowing users to prune ghost members from UI-managed (config-entry) groups directly, while YAML groups are reported as non-editable. It follows the pattern established by the person unknown-device-trackers repair and is the first application of the actionable fix pattern to a UI-managed helper.
Changes:
- Make the group repair issue
is_fixable=Trueand attachgroup_entity_id,group, andentitiesdata for the fix flow. - Add
GroupUnknownMembersFixFlow(removes members no longer in the registry/states from the group's config entry, abortsnot_editablefor YAML groups) and wire it into_REMOVE_OR_IGNORE_FLOWS. - Update
en.jsontranslations to afix_flowstructure and add tests for detection, non-detection, UI-group removal, and YAML abort.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
custom_components/spook/ectoplasms/group/repairs/unknown_members.py |
Marks the issue fixable and adds group_entity_id/group/entities data for the fix flow. |
custom_components/spook/repairs.py |
Adds GroupUnknownMembersFixFlow and its routing key; imports CONF_ENTITIES. |
custom_components/spook/translations/en.json |
Replaces the top-level description with a fix_flow menu/abort structure. |
tests/ectoplasms/group/repairs/test_unknown_members.py |
New tests covering detection, non-detection, UI-group prune, and YAML abort. |
tests/ectoplasms/group/__init__.py, tests/ectoplasms/group/repairs/__init__.py |
New test package init files. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
tests/ectoplasms/group/repairs/test_unknown_members.py (1)
1-115: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider adding coverage for
async_step_init/_menu_placeholders().Existing tests exercise
async_step_removewell, but nothing asserts thedescription_placeholdersreturned for theinitmenu step, which is why the missingentity_idplaceholder (see repairs.py comment) went unnoticed.🤖 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/group/repairs/test_unknown_members.py` around lines 1 - 115, Add test coverage for the fix flow’s init/menu step in GroupUnknownMembersFixFlow, not just async_step_remove. Create a test that calls async_step_init and verifies the returned menu result includes the expected description_placeholders from _menu_placeholders(), especially the entity_id placeholder for the affected group. Use the existing SpookRepair and async_create_fix_flow setup so the new test exercises the same issue data path that builds the menu.
🤖 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.
Inline comments:
In `@custom_components/spook/repairs.py`:
- Around line 808-834: The `async_step_remove` flow in
`RepairsGroupMembersRepairFlow` can silently succeed when
`entry_entity.config_entry_id` exists but
`hass.config_entries.async_get_entry(...)` returns `None`, so handle that stale
reference as a failure instead of falling through to `async_create_entry`. Add
an explicit branch after the `async_get_entry` lookup to abort or surface an
appropriate repair state when the config entry is missing, and only proceed with
updating `CONF_ENTITIES` when a valid entry is found.
- Around line 800-806: The menu placeholder mapping in `_menu_placeholders()` is
missing `entity_id`, so the
`group_unknown_members.fix_flow.step.init.description` text will render the raw
`{entity_id}` token. Update `_menu_placeholders()` to include an `entity_id`
entry sourced from `self.data` alongside `group` and `entities`, matching the
placeholders used by the translation.
---
Nitpick comments:
In `@tests/ectoplasms/group/repairs/test_unknown_members.py`:
- Around line 1-115: Add test coverage for the fix flow’s init/menu step in
GroupUnknownMembersFixFlow, not just async_step_remove. Create a test that calls
async_step_init and verifies the returned menu result includes the expected
description_placeholders from _menu_placeholders(), especially the entity_id
placeholder for the affected group. Use the existing SpookRepair and
async_create_fix_flow setup so the new test exercises the same issue data path
that builds the menu.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 10c86c6d-175a-4905-a012-e6e168a91a1f
📒 Files selected for processing (6)
custom_components/spook/ectoplasms/group/repairs/unknown_members.pycustom_components/spook/repairs.pycustom_components/spook/translations/en.jsontests/ectoplasms/group/__init__.pytests/ectoplasms/group/repairs/__init__.pytests/ectoplasms/group/repairs/test_unknown_members.py
b21ccf5 to
65a4473
Compare
|



Description
Turns the group unknown members repair into an actionable one. It already spots groups (UI-managed light, switch, and other groups, as well as YAML groups) that still list members which no longer exist. Now it offers to clean them up.
Selecting the issue opens a menu:
Only UI-managed (config entry) groups can be edited. A YAML group lives in
configuration.yaml, so its remove option reports that and points you at your configuration instead, the same way the person device tracker repair does.This reuses the shared remove-or-ignore fix flow base; the group flow only overrides the remove step. First application of the actionable fix pattern to a UI-managed helper.
Motivation and Context
Spook already found these; now it can fix them for you, or take you to the right place. Groups are the most common UI helper that ends up with dangling members after an entity is renamed or removed.
How has this been tested?
Types of changes
Checklist