Skip to content

Split util helpers into focused modules#1277

Merged
frenck merged 2 commits into
refactor/unknown-reference-basefrom
refactor/split-util-modules
May 27, 2026
Merged

Split util helpers into focused modules#1277
frenck merged 2 commits into
refactor/unknown-reference-basefrom
refactor/split-util-modules

Conversation

@frenckatron
Copy link
Copy Markdown
Collaborator

Description

Split custom_components/spook/util.py into three focused modules:

  • entity_filtering.py for registry lookups, template entity extraction, comma-separated entity ID handling, and unknown-reference filtering.
  • setup_helpers.py for config entry and ectoplasm setup forwarding.
  • integration_linking.py for linking and unlinking sub-integrations.

The old util.py module is removed and imports are updated to point at the module that owns each concern.

Motivation and Context

util.py mixed unrelated helper families in one large module. Splitting it along the existing concern boundaries makes the import graph clearer and reduces the amount of unrelated code a future change has to touch.

This PR is stacked on #1276 because that refactor already moves the unknown-reference repair boilerplate out of the leaf modules.

How has this been tested?

  • uv run pytest -q
  • uv run ruff check custom_components/spook tests
  • uv run ruff format --check custom_components/spook tests
  • uv run pylint custom_components/spook tests/test_util.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.

@frenckatron frenckatron added the refactor Improvement of existing code, not introducing new features. label May 27, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 27, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b24752c9-ad86-4d98-adec-0fb89535213b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/split-util-modules

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
Copy Markdown

Copilot AI left a comment

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 splits Spook’s broad utility helper module into focused modules for entity filtering, setup forwarding, and sub-integration linking, then updates imports across platform shims and repair modules.

Changes:

  • Moves ectoplasm setup forwarding helpers into setup_helpers.py.
  • Moves sub-integration symlink helpers into integration_linking.py.
  • Updates entity/reference repair modules to import filtering helpers from entity_filtering.py.

Reviewed changes

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

Show a summary per file
File Description
custom_components/spook/__init__.py Uses the new focused helper modules.
custom_components/spook/entity_filtering.py Retains registry, template, and entity filtering helpers after removing unrelated utilities.
custom_components/spook/setup_helpers.py Adds ectoplasm setup forwarding helpers.
custom_components/spook/integration_linking.py Adds sub-integration link/unlink helpers.
custom_components/spook/binary_sensor.py Updates platform forwarding import.
custom_components/spook/button.py Updates platform forwarding import.
custom_components/spook/event.py Updates platform forwarding import.
custom_components/spook/number.py Updates platform forwarding import.
custom_components/spook/select.py Updates platform forwarding import.
custom_components/spook/sensor.py Updates platform forwarding import.
custom_components/spook/switch.py Updates platform forwarding import.
custom_components/spook/time.py Updates platform forwarding import.
custom_components/spook/repairs.py Updates entity ID helper import.
custom_components/spook/ectoplasms/automation/repairs/unknown_area_references.py Updates filtering helper imports.
custom_components/spook/ectoplasms/automation/repairs/unknown_device_references.py Updates filtering helper imports.
custom_components/spook/ectoplasms/automation/repairs/unknown_entity_references.py Updates filtering helper imports.
custom_components/spook/ectoplasms/automation/repairs/unknown_floor_references.py Updates filtering helper imports.
custom_components/spook/ectoplasms/automation/repairs/unknown_label_references.py Updates filtering helper imports.
custom_components/spook/ectoplasms/automation/repairs/unknown_service_references.py Updates filtering helper imports.
custom_components/spook/ectoplasms/group/repairs/unknown_members.py Updates filtering helper imports.
custom_components/spook/ectoplasms/lovelace/repairs/unknown_entity_references.py Updates filtering helper imports.
custom_components/spook/ectoplasms/proximity/repairs/unknown_ignored_zones.py Updates filtering helper imports.
custom_components/spook/ectoplasms/proximity/repairs/unknown_tracked_entities.py Updates filtering helper imports.
custom_components/spook/ectoplasms/proximity/repairs/unknown_zone.py Updates filtering helper imports.
custom_components/spook/ectoplasms/scene/repairs/unknown_entity_references.py Updates filtering helper imports.
custom_components/spook/ectoplasms/script/repairs/unknown_area_references.py Updates filtering helper imports.
custom_components/spook/ectoplasms/script/repairs/unknown_device_references.py Updates filtering helper imports.
custom_components/spook/ectoplasms/script/repairs/unknown_entity_references.py Updates filtering helper imports.
custom_components/spook/ectoplasms/script/repairs/unknown_floor_references.py Updates filtering helper imports.
custom_components/spook/ectoplasms/script/repairs/unknown_label_references.py Updates filtering helper imports.
tests/test_util.py Updates tests to import helpers from entity_filtering.py.
pyproject.toml Adds a Python 3.13 classifier.

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

Comment thread pyproject.toml Outdated
@frenckatron frenckatron force-pushed the refactor/unknown-reference-base branch from 66b1a36 to 8cd34d2 Compare May 27, 2026 21:43
@frenckatron frenckatron force-pushed the refactor/split-util-modules branch from 18c1807 to 195472f Compare May 27, 2026 21:45
@frenck frenck requested a review from Copilot May 27, 2026 21:45
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread pyproject.toml Outdated
frenckatron and others added 2 commits May 27, 2026 23:53
util.py had grown to 746 lines mixing three unrelated concerns: registry/
template entity filtering, ectoplasm setup forwarding, and sub-integration
symlinking. Split into focused modules and rewired all 30 call sites.

Also bump pyproject.toml metadata that drifted from the codebase reality:
classifiers no longer list Python 3.11/3.12, requires-python is >=3.13.2.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@frenckatron frenckatron force-pushed the refactor/split-util-modules branch from 25c9474 to c7e8830 Compare May 27, 2026 21:54
@sonarqubecloud
Copy link
Copy Markdown

@frenck frenck merged commit b7d9037 into refactor/unknown-reference-base May 27, 2026
16 checks passed
@frenck frenck deleted the refactor/split-util-modules branch May 27, 2026 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Improvement of existing code, not introducing new features.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants