Skip to content

Split util.py (746 lines) into three focused modules#1256

Draft
frenckatron wants to merge 1 commit into
frenck:mainfrom
frenckatron:frenckatron/split-util-py
Draft

Split util.py (746 lines) into three focused modules#1256
frenckatron wants to merge 1 commit into
frenck:mainfrom
frenckatron:frenckatron/split-util-py

Conversation

@frenckatron
Copy link
Copy Markdown
Collaborator

@frenckatron frenckatron commented May 20, 2026

What

Split `custom_components/spook/util.py` (746 lines) into three focused modules:
`entity_filtering.py`, `setup_helpers.py`, `integration_linking.py`. Also fix
some pyproject metadata that drifted away from the actual codebase reality.

Why

`util.py` had become a kitchen-sink of three unrelated concerns:

  • Registry lookups, template entity extraction, comma-separated entity ID
    splitting, and unknown-reference filtering (used by ~25 repair modules).
  • Ectoplasm setup forwarding (used by `init.py` and every platform file).
  • Sub-integration symlinking (used only by `async_setup_entry` /
    `async_remove_entry`).

A 746-line module that's imported in 30 places makes it hard to reason about
what depends on what. Splitting along the existing concern lines gives each
module a single reason to change and makes the dependency graph honest.

How

  • `entity_filtering.py` (648 lines) — all entity/area/device/floor/label/
    service lookups, the cache invalidation listeners, template regex extraction,
    and `async_find_services_in_sequence`. Most of util.py's bulk lives here.
  • `setup_helpers.py` (79 lines) — `async_forward_setup_entry` and
    `async_forward_platform_entry_setups_to_ectoplasm`.
  • `integration_linking.py` (42 lines) — `link_sub_integrations` and
    `unlink_sub_integrations`.
  • All 30 caller imports rewired (no compatibility shim — `util.py` is deleted).
  • `pyproject.toml` cleanup: classifiers no longer list Python 3.11/3.12 (the
    project already requires 3.13+), and `requires-python` is bumped to
    `>=3.13.2` to match the HA pin used elsewhere.

No behavior changes — every symbol is moved verbatim.

Testing

  • `uv run ruff check custom_components/spook/` — clean.
  • `uv run ruff format --check custom_components/spook/` — 166 files already
    formatted.
  • `uv run pylint custom_components/spook/` — 9.98/10, same as before (the one
    remaining warning is a pre-existing `async_timeout` import error in
    `blueprint/services/importer.py`, unrelated to this change).
  • Smoke test: imported every one of the 30 callers via `importlib` — all
    resolve cleanly.

🤖 Generated with Claude Code


Quality Report

Changes: 34 files changed, 160 insertions(+), 141 deletions(-)

Code scan: clean

Tests: failed (command not found)

Branch hygiene: 1 issue(s)

  • Branch is not pushed to remote

Generated by Kōan post-mission quality pipeline

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>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

Important

Review skipped

Draft detected.

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: 984e2f7e-8620-4fdc-8ac7-85ac02d7d566

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

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.

@sonarqubecloud
Copy link
Copy Markdown

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