Skip to content

Z-Wave Lock: Ensure a default pin length is set - #3336

Merged
ctowns merged 2 commits into
mainfrom
zwave-default-pin-length
Nov 12, 2026
Merged

ctowns merged 2 commits into
mainfrom
zwave-default-pin-length

Conversation

@ctowns

@ctowns ctowns commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Description of Change

Z-Wave locks using lockCredentials could end up with no minPinCodeLen/maxPinCodeLen at all, which means that the pin code length then defaults to the 6-10 that is enforced by the app by default. This causes problems for users who have a lock that doesn't report their pin code length, but does support pin codes of length 4.

The User Code command class has no way to report PIN length, so only Schlage (through a configuration parameter) ever filled these in.

  • Default PIN length (4–10): Adds DEFAULT_MIN_PIN_LENGTH / DEFAULT_MAX_PIN_LENGTH to lock_utils/constants.lua. These are the PIN length limits in the Z-Wave spec.
  • lock_utils.ensure_pin_length_bounds(device): On init, emits the default min and max (not displayed) only if no value exists yet. This covers existing devices that were set up before this change. Values already present, such as ones migrated from lockCodes or reported by the lock, are left alone.
  • Schlage sub-driver:
    • Before this change, Schlage treated any existing minPinCodeLen as a length the lock had reported. If a new report differed, it assumed the lock had wiped its codes and cleared all users and credentials. With the 4–10 default in place, the lock's first real report would have triggered that wipe.
    • A new persisted field, pinLengthFromDevice, now records whether the lock itself has reported a length. The wipe only happens when the lock's own earlier length changes.
    • add_credential_handler now checks this field instead of minPinCodeLen == nil to decide whether to query parameter 16 and wait before adding the credential. Without this, the default value would stop the handler from ever asking the lock for its real length.

Summary of Completed Tests

Tested on-device with a Yale door lock. New unit tests have been added.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Channel deleted.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

zwave-lock_coverage.xml

File Coverage
All files 89% ❌
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zwave-lock/src/schlage-lock/init.lua 98% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zwave-lock/src/zwave-alarm-v1-lock/init.lua 24% ❌
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zwave-lock/src/lock_handlers/capabilities.lua 94% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zwave-lock/src/lock_handlers/zwave_responses.lua 85% ❌
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zwave-lock/src/legacy-handlers/zwave-alarm-v1-lock/init.lua 89% ❌
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zwave-lock/src/legacy-handlers/keywe-lock/init.lua 77% ❌
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zwave-lock/src/init.lua 97% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zwave-lock/src/lazy_load_subdriver.lua 57% ❌
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zwave-lock/src/legacy-handlers/samsung-lock/init.lua 94% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zwave-lock/src/legacy-handlers/schlage-lock/init.lua 95% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zwave-lock/src/samsung-lock/init.lua 87% ❌
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zwave-lock/src/lock_utils/tables.lua 98% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zwave-lock/src/lock_utils/utils.lua 89% ❌

Minimum allowed coverage is 90%

Generated by 🐒 cobertura-action against fd0a646

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Test Results

   73 files    570 suites   0s ⏱️
3 374 tests 3 374 ✅ 0 💤 0 ❌
5 413 runs  5 413 ✅ 0 💤 0 ❌

Results for commit fd0a646.

♻️ This comment has been updated with latest results.

@ctowns
ctowns force-pushed the zwave-default-pin-length branch from 4f7a7b9 to b8064df Compare November 5, 2026 23:12

@hcarter-775 hcarter-775 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.

lots and lots of little nits, but it looks fine to me.

@hcarter-775 hcarter-775 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.

Very clean! I still think we don't need to ensure the pin bounds in both added and init. I don't know how this would bite us, but things like this usually, eventually, do!

@ctowns
ctowns force-pushed the zwave-default-pin-length branch from 09ac637 to 362112a Compare November 12, 2026 05:15
@ctowns
ctowns force-pushed the zwave-default-pin-length branch from 362112a to 721c086 Compare November 12, 2026 05:40

@hcarter-775 hcarter-775 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.

The test failure appears to have been related to a transient battery test failure.

@hcarter-775

Copy link
Copy Markdown
Contributor

@ctowns I just realized we're not setting this explicitly during migration. We should do that as well.

@ctowns

ctowns commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

@ctowns I just realized we're not setting this explicitly during migration. We should do that as well.

Good catch @hcarter-775 ! I have just pushed up a small commit to address the migration case: fd0a646

@ctowns
ctowns merged commit 9b9695e into main Nov 12, 2026
22 checks passed
@ctowns
ctowns deleted the zwave-default-pin-length branch November 12, 2026 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants