Refactor: Move sync logic ownership from binary sensor to coordinator#730
Draft
Refactor: Move sync logic ownership from binary sensor to coordinator#730
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
dda8973 to
32f141d
Compare
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>
32f141d to
b1832ca
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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):async_request_sync()to execute set/clear operations with automatic retriesmark_synced()/mark_out_of_sync()for per-slot sync state managementget_sync_state()for binary sensor to read sync status_pending_retriesdict for per-slot retry trackingBinary sensor (
binary_sensor.py):is_onproperty from coordinator_retry_unsub,_retry_active,_schedule_retry,_perform_sync_operation,_cancel_retry- all moved to coordinatorInit (
__init__.py):async_update_listener(~240 lines) into focused helper functions:_ConfigDiffdataclass for computed differences_compute_config_diff(),_setup_new_platforms()_handle_locks_removed(),_handle_locks_added()_handle_slots_removed(),_handle_slots_added()_handle_slots_modified()Type of change
Additional information