From f60a867bc19a1334684ef476ce37cc8944fdceee Mon Sep 17 00:00:00 2001 From: Steven Green Date: Mon, 23 Sep 2024 16:13:50 -0700 Subject: [PATCH] Yale Zigbee Locks: Use MASTER_CODE user type When setting the code at index 0 for yale locks, the MASTER_CODE user type should be sent. --- .../zigbee-lock/src/test/test_zigbee_yale.lua | 47 +++++++++++++++++++ .../SmartThings/zigbee-lock/src/yale/init.lua | 3 +- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/drivers/SmartThings/zigbee-lock/src/test/test_zigbee_yale.lua b/drivers/SmartThings/zigbee-lock/src/test/test_zigbee_yale.lua index c31ab48eb5..6635b36477 100644 --- a/drivers/SmartThings/zigbee-lock/src/test/test_zigbee_yale.lua +++ b/drivers/SmartThings/zigbee-lock/src/test/test_zigbee_yale.lua @@ -147,6 +147,53 @@ test.register_coroutine_test( end ) +test.register_coroutine_test( + "Setting the master code should result in the correct user type being used", + function() + test.timer.__create_and_queue_test_time_advance_timer(4, "oneshot") + test.socket.capability:__queue_receive({ mock_device.id, { capability = capabilities.lockCodes.ID, command = "setCode", args = { 0, "1234", "test" } } }) + test.socket.zigbee:__expect_send( + { + mock_device.id, + DoorLock.server.commands.SetPINCode(mock_device, + 0, + DoorLockUserStatus.OCCUPIED_ENABLED, + DoorLockUserType.MASTER_USER, + "1234" + ) + } + ) + test.wait_for_events() + + test.mock_time.advance_time(4) + test.socket.zigbee:__expect_send( + { + mock_device.id, + DoorLock.server.commands.GetPINCode(mock_device, 0) + } + ) + test.wait_for_events() + + test.socket.zigbee:__queue_receive( + { + mock_device.id, + DoorLock.client.commands.GetPINCodeResponse.build_test_rx( + mock_device, + 0x00, + DoorLockUserStatus.OCCUPIED_ENABLED, + DoorLockUserType.MASTER_USER, + "1234" + ) + } + ) + test.socket.capability:__expect_send(mock_device:generate_test_message("main", + capabilities.lockCodes.codeChanged("0 set", { data = { codeName = "test"}, state_change = true })) + ) + test.socket.capability:__expect_send(mock_device:generate_test_message("main", + capabilities.lockCodes.lockCodes(json.encode({["0"] = "test"}), { visibility = { displayed = false }}))) + end +) + test.register_message_test( "Pin response reporting should be handled when the Lock User status is disabled", diff --git a/drivers/SmartThings/zigbee-lock/src/yale/init.lua b/drivers/SmartThings/zigbee-lock/src/yale/init.lua index e72d7dae3a..73e984036e 100644 --- a/drivers/SmartThings/zigbee-lock/src/yale/init.lua +++ b/drivers/SmartThings/zigbee-lock/src/yale/init.lua @@ -51,10 +51,11 @@ local set_code = function(driver, device, command) args = {command.args.codeSlot, command.args.codeName} }) else + local user_type = command.args.codeSlot == 0 and UserTypeEnum.MASTER_USER or UserTypeEnum.UNRESTRICTED device:send(LockCluster.server.commands.SetPINCode(device, command.args.codeSlot, UserStatusEnum.OCCUPIED_ENABLED, - UserTypeEnum.UNRESTRICTED, + user_type, command.args.codePIN) ) if (command.args.codeName ~= nil) then