Skip to content

zigbee-lock: centralize credential/user table updates and tighten addCredential/updateCredential validation - #3331

Merged
hcarter-775 merged 4 commits into
mainfrom
simplify-reported-cred-management
Nov 11, 2026
Merged

hcarter-775 merged 4 commits into
mainfrom
simplify-reported-cred-management

Conversation

@hcarter-775

@hcarter-775 hcarter-775 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Description of Change

Centralize how the lock's credential and user tables are updated after
a PIN is set on the lock, whether the PIN was set by a SmartThings
command or reported by the lock (sync or programming event).

addCredential

  • The credential always takes the next available credential slot.
  • userIndex 0 creates a new user for the credential; the user index is
    chosen when the lock confirms the code (next free user index).
  • A non-zero userIndex must name an existing user, and the credential
    is attached to it. An unknown userIndex returns invalidCommand
    without contacting the lock. If that user vanishes before the lock
    confirms, it is re-added rather than failing an accepted code.
  • resourceExhausted is returned up front when the credentials table is
    full, or when a new user is requested and the users table is full.
  • uses credentialName if available for the userName and credentialName,
    after code is set.

updateCredential

  • Only handled when the given userIndex already owns the credentialIndex
    (otherwise invalidCommand); a credential can no longer be moved to
    another user. Only the credential name can change.

Reported credentials

  • Codes reported by the lock without a command from us get a user and
    PIN credential via lock_utils.add_reported_credential.

Helpers

  • lock_utils.add_credential_and_user(device, args, add_user) adds a
    credential and, when add_user is true, its user afterwards so a
    failed credential add never leaves a user behind.
  • tables.next_index accepts an optional start index.

Summary of Completed Tests

Tested on-device. Unit tests updated

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Channel deleted.

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

zigbee-lock_coverage.xml

File Coverage
All files 94% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-lock/src/legacy-handlers/init.lua 95% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-lock/src/legacy-handlers/migrate.lua 98% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-lock/src/lock_utils/tables.lua 98% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-lock/src/lock_utils/utils.lua 97% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-lock/src/lock_handlers/zigbee_responses.lua 87% ❌
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-lock/src/lock_handlers/capabilities.lua 91% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-lock/src/lazy_load_subdriver.lua 57% ❌
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-lock/src/configurations.lua 95% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-lock/src/init.lua 99% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-lock/src/legacy-handlers/yale/init.lua 92% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-lock/src/samsungsds/init.lua 89% ❌

Minimum allowed coverage is 90%

Generated by 🐒 cobertura-action against af2903c

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Test Results

0 tests   0 ✅  0s ⏱️
0 suites  0 💤
0 files    0 ❌

Results for commit 1cbcfe5.

♻️ This comment has been updated with latest results.

@hcarter-775 hcarter-775 changed the title zigbee lock: use add_reported_credential for reported code slots zigbee lock: use structured utils to uniformly handle zigbee code responses Nov 4, 2026
Centralize how the lock's credential and user tables are updated after
a PIN is set on the lock, whether the PIN was set by a SmartThings
command or reported by the lock (sync or programming event).

addCredential
- The credential always takes the next available credential slot.
- userIndex 0 creates a new user for the credential; the user index is
  chosen when the lock confirms the code (next free user index).
- A non-zero userIndex must name an existing user, and the credential
  is attached to it. An unknown userIndex returns invalidCommand
  without contacting the lock. If that user vanishes before the lock
  confirms, it is re-added rather than failing an accepted code.
- resourceExhausted is returned up front when the credentials table is
  full, or when a new user is requested and the users table is full.

updateCredential
- Only handled when the given userIndex already owns the credentialIndex
  (otherwise invalidCommand); a credential can no longer be moved to
  another user. Only the credential name can change.

Reported credentials
- Codes reported by the lock without a command from us get a user and
  PIN credential via lock_utils.add_reported_credential.

Helpers
- lock_utils.add_credential_and_user(device, args, add_user) adds a
  credential and, when add_user is true, its user afterwards so a
  failed credential add never leaves a user behind.
- tables.next_index accepts an optional start index.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@hcarter-775
hcarter-775 force-pushed the simplify-reported-cred-management branch from 528c7fb to 4192673 Compare November 9, 2026 21:34
@tpmanley

Copy link
Copy Markdown
Contributor

The commit/PR title makes it sound like this is just a refactor, but there are also behavior changes. How about this instead?

zigbee-lock: centralize credential/user table updates and tighten addCredential/updateCredential validation

@tpmanley

Copy link
Copy Markdown
Contributor

The 61 tests failed for some reason. Do they just need to be run again?

userIndex = args.userIndex,
credentialIndex = args.credentialIndex,
credentialType = args.credentialType or consts.CRED_TYPE_PIN,
credentialName = args.credentialName or name,

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.

If I'm not mistaken using credentialName is a change in behavior that isn't called out in the description. I haven't checked - is this how we handle it in the other lock drivers as well?

@hcarter-775 hcarter-775 Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, but we should. It is an optional field that is currently basically not utilized. If it is used, it can effectively pass a userName to a newly created user without explicitly calling update. Description updated.

@hcarter-775

Copy link
Copy Markdown
Contributor Author

The 61 tests failed for some reason. Do they just need to be run again?

Yeah, it's a failure for Zwave lock. Unrelated to this PR.

@hcarter-775 hcarter-775 changed the title zigbee lock: use structured utils to uniformly handle zigbee code responses zigbee-lock: centralize credential/user table updates and tighten addCredential/updateCredential validation Nov 10, 2026
local credentials_full = #(tables.get_state(device, "credentials") or {}) >= tables.get_max_entries(device, "credentials")
-- if we are being asked to create a new user (index 0), this also needs a free user index.
local users_full = (user_index == 0) and #(tables.get_state(device, "users") or {}) >= tables.get_max_entries(device, "users")
if credentials_full or users_full then

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.

This is inconsistent with our plan to allow credentials to be created even if the users table is full. I don't think it's a blocker, but it looks like we have two different policies for handling this case dependent on whether the add originated from a keypad or from the capability command. Worth revisiting in the follow up ticket, but I wouldn't consider this a blocker here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this is closer to the expectation, where we don't allow a cred to be made if it can't have an associated user. I think the other case is the "problem", since we can't know that ahead of time, but yes, they both speak to the deeper problem at hand.

@hcarter-775
hcarter-775 merged commit 6a506c0 into main Nov 11, 2026
20 of 21 checks passed
@hcarter-775
hcarter-775 deleted the simplify-reported-cred-management branch November 11, 2026 19:47
shinasys added a commit to shinasys/SmartThingsEdgeDrivers that referenced this pull request Nov 12, 2026
ctowns added a commit that referenced this pull request Nov 12, 2026
Match the semantics merged for zigbee-lock in #3331.

addCredential
- userIndex selects the user, not the credential slot. 0 creates a new
  user (its index is chosen when the lock confirms the code); any other
  value must name an existing user without a credential, otherwise
  invalidCommand is returned without contacting the lock.
- The credential always takes the next free slot.
- resourceExhausted is returned up front when the credentials table is
  full, or when a new user is requested and the users table is full.
- A new user is named after credentialName when one is given.

updateCredential
- The given userIndex must already own the credential (otherwise
  invalidCommand); only the credential name can change. A credential
  can no longer be moved to another user, which left the old user
  without a credential and allowed pointing it at a missing user.

Users table
- Restore the totalUsersSupported limit on the users table.

Helpers
- add_user_and_credential becomes add_credential_and_user(device, args,
  add_user), matching zigbee-lock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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