Skip to content

Fix Z-Wave JS sync loop from stale AVAILABLE events#863

Merged
raman325 merged 1 commit intomainfrom
fix/slot-pin-sync-loop
Feb 5, 2026
Merged

Fix Z-Wave JS sync loop from stale AVAILABLE events#863
raman325 merged 1 commit intomainfrom
fix/slot-pin-sync-loop

Conversation

@raman325
Copy link
Owner

@raman325 raman325 commented Feb 5, 2026

Proposed change

Some Z-Wave locks send stale userIdStatus=AVAILABLE events after a code was successfully set, which was causing Lock Code Manager to clear coordinator data and trigger infinite sync loops.

This PR adds a _slot_expects_pin() check to ignore these stale AVAILABLE events when LCM expects a PIN on the slot (active=ON with PIN set).

Changes:

  • Add _slot_expects_pin() method to check if LCM expects a PIN on a slot
  • Add _get_slot_entity_states() helper to reduce code duplication between _slot_expects_pin() and _resolve_pin_if_masked()
  • Skip redundant push_update() calls in coordinator when data hasn't actually changed (reduces log noise)
  • Add comprehensive tests for new behavior

Type of change

  • Bugfix (non-breaking change which fixes an issue)

Additional information

  • This PR fixes or closes issue: fixes sync loop where PINs are constantly being set on slots
  • Root cause: Lock sends userIdStatus=AVAILABLE ~3 seconds after code set, clearing coordinator data

Some locks send stale userIdStatus=AVAILABLE events after a code was
successfully set, which was clearing coordinator data and triggering
infinite sync loops. Add _slot_expects_pin() check to ignore these
events when LCM expects a PIN on the slot (active=ON with PIN set).

Also:
- Extract _get_slot_entity_states() helper to reduce duplication
- Skip redundant push_update() calls when data hasn't changed

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 5, 2026 04:24
@github-actions github-actions bot added the python Pull requests that update Python code label Feb 5, 2026
@github-actions github-actions bot added the bug Something isn't working label Feb 5, 2026
@codecov
Copy link

codecov bot commented Feb 5, 2026

Codecov Report

❌ Patch coverage is 96.29630% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.99%. Comparing base (7fef34a) to head (4f25cd8).
⚠️ Report is 5 commits behind head on main.

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

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #863      +/-   ##
==========================================
- Coverage   96.00%   95.99%   -0.02%     
==========================================
  Files          29       29              
  Lines        2581     2599      +18     
  Branches       83       83              
==========================================
+ Hits         2478     2495      +17     
- Misses        103      104       +1     
Flag Coverage Δ
python 95.95% <96.29%> (-0.02%) ⬇️

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

Files with missing lines Coverage Δ
...components/lock_code_manager/providers/zwave_js.py 83.98% <100.00%> (+1.82%) ⬆️
custom_components/lock_code_manager/coordinator.py 95.58% <75.00%> (-1.34%) ⬇️

... 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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an infinite sync loop issue in Z-Wave JS lock integration caused by some locks sending stale userIdStatus=AVAILABLE events shortly after a code is successfully set. The fix adds logic to ignore these stale AVAILABLE events when Lock Code Manager (LCM) expects a PIN on the slot.

Changes:

  • Added _get_slot_entity_states() helper method to reduce code duplication between _slot_expects_pin() and _resolve_pin_if_masked()
  • Added _slot_expects_pin() method to check if LCM expects a PIN on a slot (active=ON with PIN set)
  • Modified AVAILABLE event handling to skip clearing slots when LCM expects a PIN on them
  • Optimized coordinator's push_update() to skip redundant updates when data hasn't changed
  • Added comprehensive tests for the new functionality

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
custom_components/lock_code_manager/providers/zwave_js.py Added helper methods to check slot expectations and refactored PIN resolution logic; added check to ignore stale AVAILABLE events
custom_components/lock_code_manager/coordinator.py Added optimization to skip redundant push_update calls when data unchanged
tests/providers/test_zwave_js.py Added comprehensive tests for new _slot_expects_pin() method and AVAILABLE event handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@raman325 raman325 merged commit 5318143 into main Feb 5, 2026
24 checks passed
@raman325 raman325 deleted the fix/slot-pin-sync-loop branch February 5, 2026 04:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant