Skip to content

Conversation

@raman325
Copy link
Owner

@raman325 raman325 commented Jan 4, 2026

Proposed change

This refactoring addresses the "locks out of sync" issue by centralizing sync operations in the coordinator rather than having them scattered across the binary sensor entity.

Key changes:

Coordinator (coordinator.py):

  • Add async_request_sync() to execute set/clear operations with automatic retries
  • Add mark_synced() / mark_out_of_sync() for per-slot sync state management
  • Add get_sync_state() for binary sensor to read sync status
  • Add _pending_retries dict for per-slot retry tracking
  • Infinite retries every 10 seconds until success or replaced by new request

Binary sensor (binary_sensor.py):

  • Now read-only: displays sync state via is_on property from coordinator
  • Detects out-of-sync conditions and requests sync via coordinator
  • Removed: _retry_unsub, _retry_active, _schedule_retry, _perform_sync_operation, _cancel_retry - all moved to coordinator

Init (__init__.py):

  • Split async_update_listener (~240 lines) into focused helper functions:
    • _ConfigDiff dataclass for computed differences
    • _compute_config_diff(), _setup_new_platforms()
    • _handle_locks_removed(), _handle_locks_added()
    • _handle_slots_removed(), _handle_slots_added()
    • _handle_slots_modified()
  • Main function now ~35 lines

Type of change

  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue: Addresses sync reliability concerns from PR review comments

@github-actions github-actions bot added code-quality Pull requests that improve code quality python Pull requests that update Python code labels Jan 4, 2026
@codecov
Copy link

codecov bot commented Jan 4, 2026

Codecov Report

❌ Patch coverage is 99.31507% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.19%. Comparing base (c51f323) to head (32f141d).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
custom_components/lock_code_manager/__init__.py 98.70% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #730      +/-   ##
==========================================
- Coverage   95.26%   95.19%   -0.07%     
==========================================
  Files          29       29              
  Lines        2384     2414      +30     
  Branches       88       88              
==========================================
+ Hits         2271     2298      +27     
- Misses        113      116       +3     
Flag Coverage Δ
python 95.05% <99.31%> (-0.08%) ⬇️

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

Files with missing lines Coverage Δ
...stom_components/lock_code_manager/binary_sensor.py 96.33% <100.00%> (-1.16%) ⬇️
custom_components/lock_code_manager/coordinator.py 97.36% <100.00%> (+0.44%) ⬆️
custom_components/lock_code_manager/__init__.py 97.24% <98.70%> (+0.35%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions bot added the documentation Documentation changes label Jan 15, 2026
@raman325 raman325 force-pushed the refactor/coordinator-sync-ownership branch 3 times, most recently from dda8973 to 32f141d Compare January 15, 2026 19:43
This refactoring addresses the "locks out of sync" issue by centralizing
sync operations in the coordinator rather than having them scattered
across the binary sensor entity.

Key changes:

**Coordinator (`coordinator.py`):**
- Add `async_request_sync()` to execute set/clear operations with retries
- Add `mark_synced()` / `mark_out_of_sync()` for per-slot sync state
- Add `get_sync_state()` for binary sensor to read sync status
- Add `_pending_retries` dict for per-slot retry tracking
- Infinite retries every 10 seconds until success or replaced by new request

**Binary sensor (`binary_sensor.py`):**
- Now read-only: displays sync state via `is_on` property from coordinator
- Detects out-of-sync conditions and requests sync via coordinator
- Removed: `_retry_unsub`, `_retry_active`, `_schedule_retry`,
  `_perform_sync_operation`, `_cancel_retry` - all moved to coordinator

**Init (`__init__.py`):**
- Split `async_update_listener` into focused helper functions:
  - `_ConfigDiff` dataclass for computed differences
  - `_compute_config_diff()`, `_setup_new_platforms()`
  - `_handle_locks_removed()`, `_handle_locks_added()`
  - `_handle_slots_removed()`, `_handle_slots_added()`
  - `_handle_slots_modified()`
- Main function now ~35 lines (was ~240)

**Tests:**
- Added 14 new coordinator sync operation tests
- Updated binary sensor tests for new architecture
- Fixed provider tests for coordinator-owned sync behavior

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@raman325 raman325 force-pushed the refactor/coordinator-sync-ownership branch from 32f141d to b1832ca Compare January 20, 2026 05:21
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 documentation Documentation changes python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants