Improve Z-Wave JS masked PIN and all-zeros handling#859
Merged
Conversation
- 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>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
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>
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 PR improves the Z-Wave JS provider's handling of masked PIN codes and all-zeros values returned by some locks:
New functionality:
code_slot_in_use()method to check slot status directly from Z-Wave cacheNonewhen slot is inactive, so sync logic knows a PIN exists on the lock even if we can't resolve the actual value.isnumeric()check for PIN values to handle edge casesCode quality improvements:
code_slot_in_use()result to avoid duplicate calls within_resolve_pin_if_masked()Exceptionto(KeyError, ValueError)for better debuggingTests:
code_slot_in_use()methodType of change
Additional information