Skip to content

Zigbee Lock: Support master codes and validate migration indices - #3321

Closed
hcarter-775 wants to merge 3 commits into
mainfrom
feat/zigbee-lock-master-code
Closed

hcarter-775 wants to merge 3 commits into
mainfrom
feat/zigbee-lock-master-code

Conversation

@hcarter-775

Copy link
Copy Markdown
Contributor

Description of Change

The primary thing this PR does is add master code support to the zigbee lock driver. For now, it uses the remoteOnlyUser type to specify which slots are master codes, but that should be updated soon.

Besides that, it validates all indices from the lockCodes before migrating them- this is especially useful for ensuring no 0-slotted codes are matched to a users entry, since that has a minimum of 1. It also allows any positive slot index to be tried, adds explicit index minimums to the capability definitions and moves Yale-specific handling into a yale sub-driver.

A more subtle update is that we create a more explicit 1-1 mapping between users and credentials. If a credential is added, a new user will be created, if that credential creation succeeds. The chosen user indices will follow a simple sequential process, adding the lowest user entry possible in all cases. Credentials, on the other hand, are now specifiable via setting a particular userIndex in the addCredential function. If 0 is chosen, the next available credential index will be tried- else, the specified index will be tried. This alters the current idea from being a user-first style of code creation to a credential-first style, speaking generically.

Summary of Completed Tests

Many unit tests have been updated to verify the new functionality, and many unit tests have been added to verify all new concepts. Add/migrate/crud testing has been completed on a Yale device (and soon a Kwikset device) to ensure all functionality remains intact.

Add master code support to the zigbee lock driver, allow any positive
slot index to be tried, add explicit index minimums to the capability
definitions, and move Yale-specific handling into a yale sub-driver.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Channel deleted.

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Test Results

   73 files    548 suites   0s ⏱️
3 351 tests 3 351 ✅ 0 💤 0 ❌
5 348 runs  5 348 ✅ 0 💤 0 ❌

Results for commit e1b270c.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

zigbee-lock_coverage.xml

File Coverage
All files 94% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-lock/src/init.lua 99% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-lock/src/configurations.lua 95% ✅
/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/legacy-handlers/migrate.lua 98% ✅
/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/samsungsds/init.lua 89% ❌
/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/yale/init.lua 96% ✅
/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/lock_handlers/capabilities.lua 91% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-lock/src/lock_handlers/zigbee_responses.lua 87% ❌

Minimum allowed coverage is 90%

Generated by 🐒 cobertura-action against e1b270c

@hcarter-775 hcarter-775 added the CGAI Contains code that was generated by AI label Nov 3, 2026
end
end

-- Some Yale locks may report a successful ClearPINCode for the master code (slot 0) but do not actually delete it,

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.

Do we have multiple Yale Zigbee locks that we have tested with? Is there any distinction between which ones report this but don't actually delete the code vs. those that do?

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.

We don't- this is the safe option in my opinion, between letting devices accidentally delete it, and not allowing them the option at all.

local occupied = {}
for _, entry in ipairs(t) do occupied[entry[def.match_key]] = true end
local idx = 1
local idx = def.minimum

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.

Won't this make it so that all locks will start at index 0? Even ones where we aren't tracking the master code like we are for Yale? It feels like if this slot could be used for master codes on other locks, we should leave it reserved for that.

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.

We always sync codes starting at 0 on device initialization, and this commit (e1b270c) strengthens that binding a good bit.

That commit also changes the user type from guest to master if a MASTER_CODE_CHANGED event ever comes in for a code we already store.

What I'm trying to say is that all locks, if they have a code at index 0, should tell us that prior to us doing anything. I don't think we should block index 0 from getting used just because there might be a master code on it, since we explicitly check that.

-- addCredential has no credentialIndex argument, so its userIndex argument selects the credential slot. A value
-- of 0 means "auto-assign the next available slot". The user is always new, and takes the next available user slot.
local cred_index = command.args.userIndex == 0 and tables.next_index(device, "credentials") or command.args.userIndex
local user_index = tables.next_index(device, "users")

@tpmanley tpmanley Nov 4, 2026 •

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.

As you noted, with this change calling addCredential will create a new user. Previously one could call addUser to create a user and then addCredential to add a PIN for that user, so with this change that no longer works. It's not clear to me this is the right thing to do, but I also don't think it's related to the support for master code. Could we take this change out of this PR and discuss it separately?

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.

moved: #3333

end

if user_id >= tables.get_max_entries(device, "credentials") or
if #(tables.get_state(device, "credentials") or {}) >= tables.get_max_entries(device, "credentials") or

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.

I think this change may allow it to keep reading past the number of supported slots because it no longer checks to see if the user_id is >= the max entries.

@CLAassistant

CLAassistant commented Nov 4, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@hcarter-775

Copy link
Copy Markdown
Contributor Author

@hcarter-775 hcarter-775 closed this Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AIReview CGAI Contains code that was generated by AI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants