Skip to content

fix(zwave_js): tolerate transient SetValueResult statuses on UC writes (#1251)#1256

Merged
raman325 merged 1 commit into
mainfrom
fix/zwave-js-uc-tolerate-non-ok-status
Jun 13, 2026
Merged

fix(zwave_js): tolerate transient SetValueResult statuses on UC writes (#1251)#1256
raman325 merged 1 commit into
mainfrom
fix/zwave-js-uc-tolerate-non-ok-status

Conversation

@raman325

Copy link
Copy Markdown
Owner

Proposed change

Match the 3.x tolerance for non-OK `SetValueResult` statuses on User Code CC writes.

3.x routed sets/clears through HA's `zwave_js.set_lock_usercode` / `clear_lock_usercode` services. I just re-read that service in current HA (`homeassistant/components/zwave_js/lock.py:132`): it calls `set_usercode` and never inspects `SetValueResult.status` — anything short of a Z-Wave transport error is treated as success. So a flaky Schlage UC v1 lock that responded `FAIL` intermittently was silently tolerated; the optimistic push and the next sync tick converged the slot.

The 4.x rewrite (PR #1252) added a strict status check that escalates any status outside `(SUCCESS, SUCCESS_UNSUPERVISED, WORKING)` to `CodeRejectedError` / `LockOperationFailed`. That's the regression behind TheMegamind's "code slots won't stay enabled" symptom — the first transient `FAIL` from a flaky lock disabled the slot.

Split the status set in two:

Set Statuses Action
`_UC_SET_VALUE_OK` `SUCCESS`, `SUCCESS_UNSUPERVISED`, `WORKING` silent success
`_UC_SET_VALUE_FATAL` `NO_DEVICE_SUPPORT`, `ENDPOINT_NOT_FOUND`, `NOT_IMPLEMENTED`, `INVALID_VALUE` raise `CodeRejectedError` (set) / `LockOperationFailed` (clear) — structural impossibilities
Everything else (canonically `FAIL`) log `INFO` and continue; optimistic push + sync tick converge

This restores 3.x behavior for the flaky-lock population while keeping the loud-failure surface for genuinely unrecoverable cases.

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

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.

Tests:

  • `test_uc_set_fail_status_logs_and_continues` — `FAIL` on set → returns True, INFO log, optimistic push delivered
  • `test_uc_clear_fail_status_logs_and_continues` — same for clear
  • `test_uc_set_fatal_status_raises_code_rejected` — parametrized over the 4 fatal statuses, each still raises `CodeRejectedError`
  • `test_uc_clear_fatal_status_raises_operation_failed` — same for clear
  • Replaces the old `test_uc_{set,clear}credential_failure_status*` tests that encoded the over-strict contract

🤖 Generated with Claude Code

#1251)

3.x routed UC set/clear through ``zwave_js.set_lock_usercode`` /
``zwave_js.clear_lock_usercode``, which never inspected
``SetValueResult.status``. Flaky-interview Schlage UC v1 locks that
respond with ``FAIL`` intermittently were silently tolerated; the
optimistic push + next sync tick converged the slot. The 4.x rewrite
added a strict status check that escalated any non-OK status to
``CodeRejectedError`` / ``LockOperationFailed``, which disabled the
slot on the first transient ``FAIL`` -- exactly TheMegamind's symptom
of "code slots won't stay enabled" after the #1252 fallback shipped.

Split the status set in two:

- ``_UC_SET_VALUE_FATAL`` (NO_DEVICE_SUPPORT, ENDPOINT_NOT_FOUND,
  NOT_IMPLEMENTED, INVALID_VALUE): structural impossibilities, still
  raise loudly because retrying cannot recover.
- Everything not in OK and not in FATAL (canonically ``FAIL``): log
  at INFO and let the optimistic push + sync tick converge, matching
  3.x tolerance.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Entire-Checkpoint: 62765cba5358
Copilot AI review requested due to automatic review settings June 13, 2026 03:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added python Pull requests that update Python code bug Something isn't working labels Jun 13, 2026
@raman325 raman325 requested a review from Copilot June 13, 2026 03:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@raman325 raman325 merged commit 055773c into main Jun 13, 2026
13 checks passed
@raman325 raman325 deleted the fix/zwave-js-uc-tolerate-non-ok-status branch June 13, 2026 03:48
@codecov

codecov Bot commented Jun 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.11%. Comparing base (f87e64e) to head (79282dc).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1256   +/-   ##
=======================================
  Coverage   97.11%   97.11%           
=======================================
  Files          54       54           
  Lines        6411     6416    +5     
  Branches      461      461           
=======================================
+ Hits         6226     6231    +5     
  Misses        185      185           
Flag Coverage Δ
python 97.66% <100.00%> (+<0.01%) ⬆️

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

Files with missing lines Coverage Δ
...onents/lock_code_manager/providers/_zwave_js_uc.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

[ISSUE] 4.0.2 Code rejected Credential slot for pin_code must be between 1 and 0

2 participants