fix(zha): treat set_pin_code status 3 as soft-success to stop retry loop#661
fix(zha): treat set_pin_code status 3 as soft-success to stop retry loop#661firstof9 wants to merge 1 commit into
Conversation
Some ZHA locks (e.g. Yale YRD210) return Status.undefined_0x03 (ZCL value 3, MEMORY_FULL) from set_pin_code when the target slot already holds any code. The previous code treated every non-zero status as a hard failure, logged an ERROR, and returned False — causing the coordinator sync loop to retry endlessly and flood the logs every ~30s. Treat status 3 as a firmware-level 'slot occupied' response: preserve the existing cached code (or fall back to the code being set if the cache is empty) and return True to signal success. Log the event at DEBUG level so it is visible in debug logs but invisible in normal operation. All other non-zero statuses continue to be treated as hard failures. Adds three new test cases covering: - Status 3 with no prior cache entry (uses the code being set) - Status 3 with an existing cached entry (preserves existing code) - Status 3 delivered as a list element Fixes FutureTense#660
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #661 +/- ##
==========================================
+ Coverage 84.14% 92.16% +8.01%
==========================================
Files 10 41 +31
Lines 801 4798 +3997
Branches 0 30 +30
==========================================
+ Hits 674 4422 +3748
- Misses 127 376 +249
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Code Review Summary — PR #661: fix(zha): treat set_pin_code status 3 as soft-success🔴 Critical
|
Summary
Fixes the infinite retry/log-flooding bug reported in #660 for ZHA-integrated Zigbee locks (Yale YRD210 and likely others).
Root Cause
Some ZHA locks return
Status.undefined_0x03(ZCL value3, defined in the Door Lock spec asMEMORY_FULL) fromset_pin_codewhen the target slot already holds any code. The PIN is physically accepted by the lock — only the response status is unexpected.The previous code treated every non-zero status as a hard failure, logged an
ERROR, and returnedFalse. This caused the coordinator's sync loop to retry endlessly (~every 30s), flooding the logs while the lock continued to work correctly.Fix
In
async_set_usercode()inproviders/zha.py, status3is now handled as a firmware-level "slot occupied" response:Trueto signal success and stop the retry cycleFalse)Tests
Three new test cases added to
tests/providers/test_zha.py:test_set_usercode_status_3_no_existing_cache— status 3 with no prior cache entry → cache uses the code being settest_set_usercode_status_3_preserves_existing_cache— status 3 with an existing cached entry → preserves the existing cached codetest_set_usercode_status_list_3_soft_success— status 3 delivered as a list element (alternate ZCL response format)All 914 tests pass; coverage remains at 92%.
Type of change
Additional information