Skip to content

Refactor: Decouple availability-only Keymaster entities from coordinator value fan-out #686

Description

@tykeal

Part of #670

Summary

Buttons and code-slot event entities carry no coordinator-derived value; move them off the value
fan-out with a targeted availability signal and audit whether any config entities' coordinator
coupling can be reduced without losing parent/child inheritance, Rental Control writes, provider
PIN read-backs, or access-limit decrements. This implements the new secondary goal raised by
@raman325: reduce entity↔coordinator coupling where safe.

Scope / changes

  • Refactor button coordinator handling at button.py:84-101; it currently updates only
    availability and writes state.
  • Refactor the code-slot event coordinator-update handler at event.py:137-152; the displayed
    "last used" value remains bus-driven, and coordinator updates only set availability.
  • Revisit the base CoordinatorEntity binding at entity.py:61 for these availability-only
    entity types so they no longer subscribe to the coordinator value fan-out.
  • Add a lightweight targeted availability dispatch signal fired when a lock's connected state or
    code-slot set changes, and subscribe buttons/code-slot event entities to that signal instead.
  • Value-bearing config entities are out of scope for detachment: text name/PIN entities,
    datetime/time entities, number access-limit count entities, and config switches must remain
    coordinator-driven because parent→child inheritance, Rental Control writes, provider PIN
    read-backs, and access-limit decrements propagate through coordinator data. They are in scope
    only for a written coupling audit.

Plan reference

New secondary goal in §2 Goals; complements §5.9 change-detection (task-3) and §5.2/§5.8
per-lock work.

Dependencies

Depends on: #677, #681

Acceptance criteria

  • Availability-only entities (buttons and code-slot events) no longer subscribe to the value
    fan-out and no longer re-render on unrelated coordinator updates.
  • Buttons and code-slot events still update availability correctly on connect/disconnect and
    slot add/remove transitions, with tests.
  • A written audit note identifies which config entities could be decoupled and why the rest
    cannot be detached without losing parent/child, Rental Control, provider read-back, or
    access-limit propagation.
  • Validation passes: ruff check custom_components/ tests/, mypy custom_components/keymaster/,
    and the targeted platform/entity tests for buttons, events, and audited config entities.

Risk / notes

Main risk is stale availability if the targeted signal misses a connect, disconnect, or slot-set
transition. Keep value-bearing entities coordinator-driven. This is largely an optimization because
#677 change-detection already neutralizes the storm contribution by making availability-only
entities no-op unless availability flips.

Size

M

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions