Skip to content

refactor: prune dead provider helpers and collapse SlotEntities builders#1266

Merged
raman325 merged 1 commit into
mainfrom
chore/simplify-from-audit
Jun 16, 2026
Merged

refactor: prune dead provider helpers and collapse SlotEntities builders#1266
raman325 merged 1 commit into
mainfrom
chore/simplify-from-audit

Conversation

@raman325

Copy link
Copy Markdown
Owner

Proposed change

Mechanical cleanups surfaced by an audit of providers/_util.py and websocket.py — net -87 lines across production + tests, zero behavior change.

providers/_util.py

  • Delete make_legacy_tagged_name — zero non-test callers; the providers it was reserved for already emit the canonical lcm:<slot>: format.
  • Inline parse_tag_with_rewrite into parse_tag — single caller, vestigial needs_rewrite boolean (no consumer ever flipped on it).
  • Legacy [LCM:<slot>] is now strictly read-only: parse_tag still recognizes it so older lock-stored names continue to identify as LCM-owned until the next write rewrites them in canonical form.

websocket.py

  • Extract _build_slot_entities(ent_reg, entry_id, slot_num) — the per-lock iterator (_get_slot_entity_ids) and the per-slot subscription resolver now share one unique_id formula and one populated SlotEntities shape (the two previously diverged on config_entry_id vs event_entity_id).
  • Drop _get_slot_entity_data — its only call site now invokes _build_slot_entities directly.
  • Change _get_slot_metadata() to take pre-resolved entities. _serialize_lock_coordinator was walking the entity registry twice per call (once via _get_slot_metadata, once directly); now it walks once and reuses.

Tests

  • Port the rich match-priority cases from TestParseTagWithRewrite onto TestParseTag (adapted to 2-tuple). No coverage loss for parse_tag.
  • test_websocket mocks updated from _get_slot_entity_data to _build_slot_entities.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (which adds functionality)
  • Code quality improvements to existing code or addition of tests

Additional information

Surfaced by a codebase-wide audit for unnecessary complexity. Larger items found in the same audit (parallel circuit breakers in coordinator vs sync, twin confirmation paths, _verified + _pending_writes parallel state) are intentionally not part of this PR — they need a design call, not a mechanical refactor.

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Local tests pass. Your PR cannot be merged unless tests pass

🤖 Generated with Claude Code

* `providers/_util.py`: delete `make_legacy_tagged_name` (zero
  production callers) and inline `parse_tag_with_rewrite` into
  `parse_tag` (single caller, vestigial `needs_rewrite` signal). The
  legacy `[LCM:<slot>]` format is now read-only -- `parse_tag` still
  recognizes it so older lock-stored names continue to identify as
  LCM-owned until the next write rewrites them.

* `websocket.py`: extract `_build_slot_entities()` so the per-lock
  iterator (`_get_slot_entity_ids`) and the per-slot subscription
  resolver share one unique_id formula and one `SlotEntities` shape.
  `_get_slot_metadata()` now takes pre-resolved entities, removing the
  duplicate registry walk in `_serialize_lock_coordinator`. Drops the
  thin `_get_slot_entity_data` wrapper -- its only caller now calls
  `_build_slot_entities` directly.

* Tests: port the rich match-priority cases from `TestParseTagWithRewrite`
  onto `TestParseTag` (adapted to 2-tuple); switch `test_websocket`
  mocks from `_get_slot_entity_data` to `_build_slot_entities`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 16, 2026 02:39

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added python Pull requests that update Python code code-quality Pull requests that improve code quality labels Jun 16, 2026
@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.16%. Comparing base (4657eab) to head (6d17239).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1266   +/-   ##
=======================================
  Coverage   97.15%   97.16%           
=======================================
  Files          54       54           
  Lines        6543     6521   -22     
  Branches      460      460           
=======================================
- Hits         6357     6336   -21     
+ Misses        186      185    -1     
Flag Coverage Δ
python 97.71% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...om_components/lock_code_manager/providers/_util.py 100.00% <100.00%> (ø)
custom_components/lock_code_manager/websocket.py 98.23% <100.00%> (+0.16%) ⬆️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@raman325 raman325 merged commit 48a76a3 into main Jun 16, 2026
18 checks passed
@raman325 raman325 deleted the chore/simplify-from-audit branch June 16, 2026 02:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-quality Pull requests that improve code quality python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants