Skip to content

Redirect repairs to the first view with unknown entities#1172

Open
piitaya wants to merge 3 commits intofrenck:mainfrom
piitaya:unknown_entity_redirect_view
Open

Redirect repairs to the first view with unknown entities#1172
piitaya wants to merge 3 commits intofrenck:mainfrom
piitaya:unknown_entity_redirect_view

Conversation

@piitaya
Copy link
Contributor

@piitaya piitaya commented Jan 20, 2026

Description

Redirect repairs to the first view with unknown entities

Motivation and Context

Previously, the "unknown entity references" repair always linked to view 0 regardless of which view actually contained the missing entity. This made it harder for users to find and fix the issue, especially in dashboards with many views.

Now the repair link points directly to the first view that contains an unknown entity, using the view's path if set or falling back to the view index.

How has this been tested?

Manual testing with dashboards containing multiple views where unknown entities exist in views other than the first one.

Screenshots (if appropriate):

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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 20, 2026

Warning

Rate limit exceeded

@piitaya has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 3 minutes and 2 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 5ff1b85 and b444268.

📒 Files selected for processing (1)
  • custom_components/spook/ectoplasms/lovelace/repairs/unknown_entity_references.py
📝 Walkthrough

Walkthrough

The entity extraction was refactored: __async_extract_entities now returns a dict mapping entity_id -> view_path (int|string) instead of a set. Call sites were updated to use mapping keys for unknown-entity checks and mapping values to construct edit URLs using /{url_path}/{first_view_path}?edit=1.

Changes

Cohort / File(s) Summary
Entity extraction & inspector
custom_components/spook/ectoplasms/lovelace/repairs/unknown_entity_references.py
Changed __async_extract_entities return type from set[str] to `dict[str, int

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

new-feature

Suggested reviewers

  • frenck

Poem

🐰 I hopped through dashboards, keen and bright,
Collected entities, noted each sight,
From sets to maps my findings grew,
Paths and IDs now tied true,
A tiny hop — one tidy fix! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: redirecting repair links to the first view with unknown entities instead of always using view 0.
Description check ✅ Passed The description is well-related to the changeset, explaining the motivation (users struggling to find issues across multiple views), the implementation (using view path or index), and testing approach.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In
`@custom_components/spook/ectoplasms/lovelace/repairs/unknown_entity_references.py`:
- Around line 71-72: unknown_entities is a set so using
next(iter(unknown_entities)) yields an arbitrary entity; to pick the first
unknown entity by view order, iterate the insertion-ordered mapping
extracted_entities and select the first key present in unknown_entities, then
assign its value to first_view_path (update the code around first_view_path =
extracted_entities[next(iter(unknown_entities))] to search
extracted_entities.keys() for the first key in unknown_entities).

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In
`@custom_components/spook/ectoplasms/lovelace/repairs/unknown_entity_references.py`:
- Around line 71-76: The StopIteration is caused by keys in extracted_entities
containing comma-separated raw strings while async_filter_known_entity_ids
returns split entity IDs; update __async_extract_entities to normalize/split and
strip comma-separated entity strings into individual keys (e.g., produce entries
for "light.a" and "light.b" rather than "light.a, light.b") so the lookup used
by the next(...) that computes first_view_path against unknown_entities
succeeds; ensure extracted_entities remains a mapping from single entity_id ->
path and adjust any deduplication logic accordingly.

@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant