Skip to content

Offer to clean up unknown members in groups - #1383

Merged
frenck merged 1 commit into
mainfrom
frenck/group-fix-flow
Jul 5, 2026
Merged

frenck merged 1 commit into
mainfrom
frenck/group-fix-flow

Conversation

@frenck

@frenck frenck commented Jul 5, 2026

Copy link
Copy Markdown
Owner

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:

  • Remove these members drops the missing members from the group. For a UI-managed group it edits the group's config entry, keeping every member that still exists (recomputed at fix time, so a member that came back is kept), and the group reloads without the ghosts.
  • Let me fix it myself takes you to the Helpers page.
  • Keep them, stop telling me ignores the issue.

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?

  • Detection of a group with a missing member (reported as fixable), and non-detection of a group whose members all exist.
  • The remove option prunes the missing members from a UI group's config entry.
  • A YAML group aborts the remove with the cannot-edit message.
  • Full suite green (691 passed), ruff + pylint (10.00/10) + prettier clean.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Other

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

Copilot AI review requested due to automatic review settings July 5, 2026 13:46
@frenck frenck added the new-feature New features or options. label Jul 5, 2026
@coderabbitai

coderabbitai Bot commented Jul 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: cbe5a605-703d-4137-aaef-42d02d24490f

📥 Commits

Reviewing files that changed from the base of the PR and between b21ccf5 and 65a4473.

📒 Files selected for processing (6)
  • custom_components/spook/ectoplasms/group/repairs/unknown_members.py
  • custom_components/spook/repairs.py
  • custom_components/spook/translations/en.json
  • tests/ectoplasms/group/__init__.py
  • tests/ectoplasms/group/repairs/__init__.py
  • tests/ectoplasms/group/repairs/test_unknown_members.py
✅ Files skipped from review due to trivial changes (2)
  • tests/ectoplasms/group/repairs/init.py
  • tests/ectoplasms/group/init.py
🚧 Files skipped from review as they are similar to previous changes (4)
  • custom_components/spook/ectoplasms/group/repairs/unknown_members.py
  • tests/ectoplasms/group/repairs/test_unknown_members.py
  • custom_components/spook/translations/en.json
  • custom_components/spook/repairs.py

📝 Walkthrough

Walkthrough

Adds 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.

Changes

Group Unknown Members Repair Flow

Layer / File(s) Summary
Issue payload includes described entities
custom_components/spook/ectoplasms/group/repairs/unknown_members.py
async_inspect computes described once and reuses it for both the issue data["entities"] and translation_placeholders["entities"].
GroupUnknownMembersFixFlow implementation and registration
custom_components/spook/repairs.py
Adds CONF_ENTITIES import and GroupUnknownMembersFixFlow, which aborts with not_editable for YAML groups or prunes missing members from a UI group's config entry options; registers the flow in _REMOVE_OR_IGNORE_FLOWS.
Translations for fix flow
custom_components/spook/translations/en.json
Rewrites entity.issues.group_unknown_members into a structured fix_flow with step.init menu options and abort outcomes.
Tests for unknown members repair and fix flow
tests/ectoplasms/group/__init__.py, tests/ectoplasms/group/repairs/__init__.py, tests/ectoplasms/group/repairs/test_unknown_members.py
Adds package docstrings and tests for issue creation/absence, UI-group pruning, and YAML-group abort behavior.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

  • frenck/spook#1073: Both PRs touch the group_unknown_members issue translation placeholders and the entities text used for unknown members.
  • frenck/spook#1369: Both change SpookRepair.async_inspect in the same area to build described unknown-entity text for the issue payload.
  • frenck/spook#1382: Both modify custom_components/spook/repairs.py around shared remove-or-ignore fix-flow behavior.

Suggested labels: enhancement

Poem

A rabbit hops where groups once sighed,
With missing members named and tried.
Spook prunes the ghosts, then bounces bright,
And helpers page may guide things right. 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the new group unknown-members cleanup repair flow.
Description check ✅ Passed The description accurately matches the changes, including the actionable fix flow, UI-managed group edits, and YAML group handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch frenck/group-fix-flow

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov-commenter

codecov-commenter commented Jul 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.47619% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.67%. Comparing base (64f6b54) to head (65a4473).

Files with missing lines Patch % Lines
custom_components/spook/repairs.py 90.00% 0 Missing and 2 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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=True and attach group_entity_id, group, and entities data for the fix flow.
  • Add GroupUnknownMembersFixFlow (removes members no longer in the registry/states from the group's config entry, aborts not_editable for YAML groups) and wire it into _REMOVE_OR_IGNORE_FLOWS.
  • Update en.json translations to a fix_flow structure 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.

Comment thread custom_components/spook/repairs.py Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
tests/ectoplasms/group/repairs/test_unknown_members.py (1)

1-115: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider adding coverage for async_step_init / _menu_placeholders().

Existing tests exercise async_step_remove well, but nothing asserts the description_placeholders returned for the init menu step, which is why the missing entity_id placeholder (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

📥 Commits

Reviewing files that changed from the base of the PR and between 64f6b54 and b21ccf5.

📒 Files selected for processing (6)
  • custom_components/spook/ectoplasms/group/repairs/unknown_members.py
  • custom_components/spook/repairs.py
  • custom_components/spook/translations/en.json
  • tests/ectoplasms/group/__init__.py
  • tests/ectoplasms/group/repairs/__init__.py
  • tests/ectoplasms/group/repairs/test_unknown_members.py

Comment thread custom_components/spook/repairs.py Resolved
Comment thread custom_components/spook/repairs.py Resolved
@frenck
frenck force-pushed the frenck/group-fix-flow branch from b21ccf5 to 65a4473 Compare July 5, 2026 14:03
@sonarqubecloud

sonarqubecloud Bot commented Jul 5, 2026

Copy link
Copy Markdown

@frenck
frenck merged commit 32a35dc into main Jul 5, 2026
19 checks passed
@frenck
frenck deleted the frenck/group-fix-flow branch July 5, 2026 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-feature New features or options.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants