Skip to content

Improve Z-Wave JS masked PIN and all-zeros handling#859

Merged
raman325 merged 2 commits intomainfrom
fix/zwave-masked-pin-handling
Feb 4, 2026
Merged

Improve Z-Wave JS masked PIN and all-zeros handling#859
raman325 merged 2 commits intomainfrom
fix/zwave-masked-pin-handling

Conversation

@raman325
Copy link
Owner

@raman325 raman325 commented Feb 4, 2026

Proposed change

This PR improves the Z-Wave JS provider's handling of masked PIN codes and all-zeros values returned by some locks:

New functionality:

  • Add code_slot_in_use() method to check slot status directly from Z-Wave cache
  • Handle all-zeros PIN values (e.g., "0000") as cleared when the slot is confirmed not in use
  • Return masked value instead of None when slot is inactive, so sync logic knows a PIN exists on the lock even if we can't resolve the actual value
  • Remove the .isnumeric() check for PIN values to handle edge cases

Code quality improvements:

  • Cache code_slot_in_use() result to avoid duplicate calls within _resolve_pin_if_masked()
  • Narrow exception handling from Exception to (KeyError, ValueError) for better debugging
  • Simplify docstrings across coordinator, websocket, and documentation files

Tests:

  • Add tests for code_slot_in_use() method
  • Add tests for all-zeros handling edge cases
  • Update existing tests to reflect new behavior

Type of change

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

Additional information

  • This PR fixes edge cases where locks return all-zeros or masked values in unexpected situations
  • The changes improve sync loop prevention by ensuring masked values are properly handled

- Add code_slot_in_use() method to check slot status from Z-Wave cache
- Handle all-zeros PIN values as cleared when slot is not in use
- Return masked value instead of None when slot inactive (helps sync logic)
- Remove .isnumeric() check for PIN values
- Cache code_slot_in_use() result to avoid duplicate calls
- Narrow exception handling from Exception to (KeyError, ValueError)
- Update tests for new behavior

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 4, 2026 01:38
@github-actions github-actions bot added python Pull requests that update Python code documentation Documentation changes bug Something isn't working labels Feb 4, 2026
@codecov
Copy link

codecov bot commented Feb 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.00%. Comparing base (2c1eb31) to head (02d240d).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #859      +/-   ##
==========================================
- Coverage   96.03%   96.00%   -0.03%     
==========================================
  Files          29       29              
  Lines        2573     2581       +8     
  Branches       83       83              
==========================================
+ Hits         2471     2478       +7     
- Misses        102      103       +1     
Flag Coverage Δ
python 95.96% <100.00%> (-0.03%) ⬇️

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

Files with missing lines Coverage Δ
custom_components/lock_code_manager/coordinator.py 96.92% <ø> (ø)
...components/lock_code_manager/providers/zwave_js.py 82.15% <100.00%> (-0.25%) ⬇️
custom_components/lock_code_manager/websocket.py 95.92% <ø> (ø)

... 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 improves the Z-Wave JS lock provider's handling of masked PIN codes and all-zeros values returned by some locks, addressing edge cases that could cause sync issues.

Changes:

  • Added code_slot_in_use() method to check slot status directly from Z-Wave cache with narrow exception handling
  • Enhanced _resolve_pin_if_masked() to handle all-zeros values as cleared when slot is confirmed not in use, and return masked values when slot status cannot be determined
  • Removed .isnumeric() check to handle non-standard PIN formats
  • Simplified docstrings across multiple files for better clarity

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
custom_components/lock_code_manager/providers/zwave_js.py Core implementation: added code_slot_in_use() method and improved _resolve_pin_if_masked() logic for masked/all-zeros handling
tests/providers/test_zwave_js.py Comprehensive test updates and new tests for code_slot_in_use(), all-zeros handling, and masked value behavior
docs/development/provider-state-management.md Simplified docstrings for provider methods
docs/development/adding-a-provider.md Simplified docstrings for provider implementation guidance
custom_components/lock_code_manager/coordinator.py Simplified push_update() docstring
custom_components/lock_code_manager/websocket.py Corrected "Returns:" to "Sends:" for websocket command documentation

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

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@raman325 raman325 merged commit 72b2672 into main Feb 4, 2026
8 of 10 checks passed
@raman325 raman325 deleted the fix/zwave-masked-pin-handling branch February 4, 2026 01:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant