Skip to content

Ignore event payloads in automation repair checks - #1312

Merged
frenck merged 1 commit into
mainfrom
fix/automation-event-type-entities
Jun 22, 2026
Merged

frenck merged 1 commit into
mainfrom
fix/automation-event-type-entities

Conversation

@frenckatron

Copy link
Copy Markdown
Collaborator

Description

Spook now ignores event-trigger payload metadata when checking automation references.

This keeps event_type values like timer.finished out of the unknown entity repair, while still checking real entities from event_data.entity_id.

It also ignores event_data.device_id values for event triggers in the unknown device repair, since those values are event payload data and not Home Assistant device registry references.

Motivation and Context

Event trigger payloads can contain strings that look like Home Assistant references, but are not references owned by the automation.

Fixes #1213.
Refs #1081.

How has this been tested?

  • uv run pytest tests/ectoplasms/automation/repairs -q
  • uv run pytest tests/ectoplasms/automation/repairs tests/test_translations.py -q
  • uv run ruff format --check .
  • uv run ruff check --output-format=github .
  • uv run --with pre-commit pre-commit run pylint --files custom_components/spook/ectoplasms/automation/repairs/unknown_entity_references.py custom_components/spook/ectoplasms/automation/repairs/unknown_device_references.py tests/ectoplasms/automation/repairs/test_unknown_entity_references.py tests/ectoplasms/automation/repairs/test_unknown_device_references.py

Screenshots (if appropriate):

Not applicable.

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

coderabbitai Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8f15ee52-82c0-4905-9b51-7a21a65ec5c4

📥 Commits

Reviewing files that changed from the base of the PR and between f751a9e and eca7a61.

📒 Files selected for processing (4)
  • custom_components/spook/ectoplasms/automation/repairs/unknown_device_references.py
  • custom_components/spook/ectoplasms/automation/repairs/unknown_entity_references.py
  • tests/ectoplasms/automation/repairs/test_unknown_device_references.py
  • tests/ectoplasms/automation/repairs/test_unknown_entity_references.py

📝 Walkthrough

Walkthrough

Two recursive helper functions are added to the automation repair modules: extract_event_data_device_ids_from_trigger_config for device references and extract_event_types_from_trigger_config for entity references. Both are used in _async_compute_unknown_references to subtract trigger event metadata (e.g. event_type: timer.finished, event_data.device_id) before reporting unknown references. New test files cover both fixes.

Changes

Automation Repair: Suppress Event Trigger False Positives

Layer / File(s) Summary
Extract event_data device IDs and filter from unknown device references
custom_components/spook/ectoplasms/automation/repairs/unknown_device_references.py, tests/ectoplasms/automation/repairs/test_unknown_device_references.py
Adds extract_event_data_device_ids_from_trigger_config to recursively collect event_data.device_id values from event-type triggers, then subtracts them from entity.referenced_devices in _async_compute_unknown_references before filtering. New test verifies that event_data.device_id values are not reported as unknown device references.
Extract event_type strings and filter from unknown entity references
custom_components/spook/ectoplasms/automation/repairs/unknown_entity_references.py, tests/ectoplasms/automation/repairs/test_unknown_entity_references.py
Adds extract_event_types_from_trigger_config to recursively collect event_type values from trigger config, then removes them from all_entities in _async_compute_unknown_references before known-entity filtering. Tests verify timer.finished-style event types are excluded while event_data.entity_id references are still reported.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • frenck/spook#977: Modifies the same SpookRepair._async_compute_unknown_references logic in unknown_entity_references.py for trigger/template-based entity extraction and filtering.
  • frenck/spook#1275: Adds automation unknown-reference extractor test coverage for trigger config handling including ensuring event_type strings are not treated as entity IDs.
  • frenck/spook#1276: Refactors the base-class _async_compute_unknown_references in both unknown_device_references.py and unknown_entity_references.py that this PR builds upon.

Poem

🐇 Hippity hop, the ghost said "boo!"
timer.finished — an event, not an entity, it's true!
A device_id in event_data? Not unknown, no fear,
The recursive helper sniffed it out, crystal clear.
No more false alarms from triggers in the night,
This bunny patched the phantom — everything's alright! 👻

✨ 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 fix/automation-event-type-entities

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.

@frenckatron frenckatron added the bugfix Inconsistencies or issues which will cause a problem for users or implementors. label Jun 22, 2026
@frenckatron
frenckatron force-pushed the fix/automation-event-type-entities branch from 00f2988 to eca7a61 Compare June 22, 2026 21:48
@frenck
frenck requested a review from Copilot June 22, 2026 21:50

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 fixes false-positive “unknown entity/device reference” repairs caused by event-trigger payload metadata being interpreted as Home Assistant registry references in automations.

Changes:

  • Excludes event_type strings from unknown-entity reference detection (while still scanning event_data.entity_id).
  • Excludes event_data.device_id values in event triggers from unknown-device reference detection.
  • Adds/extends regression tests to cover the corrected behavior for both entity and device repairs.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
custom_components/spook/ectoplasms/automation/repairs/unknown_entity_references.py Filters out event trigger event_type values from the unknown-entity repair computation.
custom_components/spook/ectoplasms/automation/repairs/unknown_device_references.py Filters out event trigger event_data.device_id values from the unknown-device repair computation.
tests/ectoplasms/automation/repairs/test_unknown_entity_references.py Adds regression coverage ensuring event event_type does not get treated/reported as an unknown entity reference.
tests/ectoplasms/automation/repairs/test_unknown_device_references.py Adds regression coverage ensuring event payload event_data.device_id does not get treated/reported as an unknown device reference.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@frenck
frenck marked this pull request as ready for review June 22, 2026 22:00
@frenck
frenck merged commit 6bb2fd6 into main Jun 22, 2026
20 checks passed
@frenck
frenck deleted the fix/automation-event-type-entities branch June 22, 2026 22:02
@sonarqubecloud

Copy link
Copy Markdown

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

Labels

bugfix Inconsistencies or issues which will cause a problem for users or implementors.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrectly Identified Entity

3 participants