Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 39 additions & 20 deletions drivers/SmartThings/matter-lock/src/new-matter-lock/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1554,15 +1554,29 @@ local function clear_user_response_handler(driver, device, ib, response)
device.log.warn(string.format("Failed to clear user: %s", status))
end

-- Update commandResult
local command_result_info = {
commandName = cmdName,
userIndex = userIdx,
statusCode = status
}
device:emit_event(capabilities.lockUsers.commandResult(
command_result_info, {state_change = true, visibility = {displayed = false}}
))
-- This occurs in the "defaultSchedule" command failure path, when a guest user's credentials are set but
-- the scheduling fails during default setup. In this case, those set credentials should be removed, and we
-- wait to log lock credentials (note: as a "failure", though it technically succeeded) until here.
if cmdName == "defaultSchedule" then
local command_result_info = {
commandName = "addCredential",
userIndex = userIdx,
statusCode = "failure"
}
device:emit_event(capabilities.lockCredentials.commandResult(
command_result_info, {state_change = true, visibility = {displayed = false}}
))
device:set_field(lock_utils.BUSY_STATE, false, {persist = true})
else
local command_result_info = {
commandName = cmdName,
userIndex = userIdx,
statusCode = status
}
device:emit_event(capabilities.lockUsers.commandResult(
command_result_info, {state_change = true, visibility = {displayed = false}}
))
end
device:set_field(lock_utils.BUSY_STATE, false, {persist = true})
end

Expand Down Expand Up @@ -2418,17 +2432,22 @@ local function set_year_day_schedule_handler(driver, device, ib, response)
local cmdName = "addCredential"
local credIdx = device:get_field(lock_utils.CRED_INDEX)

-- Update commandResult
local command_result_info = {
commandName = cmdName,
userIndex = userIdx,
credentialIndex = credIdx,
statusCode = status
}
device:emit_event(capabilities.lockCredentials.commandResult(
command_result_info, {state_change = true, visibility = {displayed = false}}
))
device:set_field(lock_utils.BUSY_STATE, false, {persist = true})
if status == "success" then
-- Update commandResult
local command_result_info = {
commandName = cmdName,
userIndex = userIdx,
credentialIndex = credIdx,
statusCode = status
}
device:emit_event(capabilities.lockCredentials.commandResult(
command_result_info, {state_change = true, visibility = {displayed = false}}
))
device:set_field(lock_utils.BUSY_STATE, false, {persist = true})
else
local ep = find_default_endpoint(device, clusters.DoorLock.ID)
device:send(DoorLock.server.commands.ClearUser(device, ep, userIdx))
end
return
end

Expand Down
136 changes: 134 additions & 2 deletions drivers/SmartThings/matter-lock/src/test/test_new_matter_lock.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ local mock_device = test.mock_device.build_test_matter_device({
cluster_id = DoorLock.ID,
cluster_type = "SERVER",
cluster_revision = 1,
feature_map = 0x0181, -- PIN & USR & COTA
feature_map = 0x0591, -- PIN & WDSCH & USR & COTA & YDSCH
}
},
device_types = {
Expand Down Expand Up @@ -76,7 +76,7 @@ local function test_init()
test.socket.capability:__expect_send(
mock_device:generate_test_message("main", capabilities.lock.supportedLockCommands({"lock", "unlock"}, {visibility = {displayed = false}}))
)
mock_device:expect_metadata_update({ profile = "lock-user-pin" })
mock_device:expect_metadata_update({ profile = "lock-user-pin-schedule" })
mock_device:expect_metadata_update({ provisioning_state = "PROVISIONED" })
end

Expand Down Expand Up @@ -2100,4 +2100,136 @@ test.register_coroutine_test(
}
)

-- mock_device:set_field(lock_utils.COTA_CRED, "654123", {persist = true}) --overwrite random cred for test expectation
test.register_coroutine_test(
"Add Guest User and failure response ",
function()
test.socket.capability:__queue_receive(
{
mock_device.id,
{
capability = capabilities.lockCredentials.ID,
command = "addCredential",
args = {0, "guest", "pin", "654123"}
},
}
)
test.socket.matter:__expect_send(
{
mock_device.id,
DoorLock.server.commands.SetCredential(
mock_device, 1, -- endpoint
DoorLock.types.DataOperationTypeEnum.ADD, -- operation_type
DoorLock.types.CredentialStruct(
{credential_type = DoorLock.types.CredentialTypeEnum.PIN, credential_index = 1}
), -- credential
"654123", -- credential_data
nil, -- user_index
nil, -- user_status
DoorLock.types.UserTypeEnum.SCHEDULE_RESTRICTED_USER -- user_type
),
}
)
test.wait_for_events()
test.socket.matter:__queue_receive(
{
mock_device.id,
DoorLock.client.commands.SetCredentialResponse:build_test_command_response(
mock_device, 1,
DoorLock.types.DlStatus.SUCCESS, -- status
1, -- user_index
2 -- next_credential_index
),
}
)
test.socket.capability:__expect_send(
mock_device:generate_test_message(
"main",
capabilities.lockUsers.users({{userIndex = 1, userType = "guest"}}, {visibility={displayed=false}})
)
)
test.socket.capability:__expect_send(
mock_device:generate_test_message(
"main",
capabilities.lockCredentials.credentials(
{{credentialIndex=1, credentialType="pin", userIndex=1}}, {visibility={displayed=false}}
)
)
)
test.socket.matter:__expect_send(
{
mock_device.id,
DoorLock.server.commands.SetYearDaySchedule(
mock_device, 1, -- endpoint
1, -- year_day_index
1, -- user_index
0, -- local_start_time
0xffffffff -- local_end_time
),
}
)
test.wait_for_events()
test.socket.matter:__queue_receive(
{
mock_device.id,
DoorLock.server.commands.SetYearDaySchedule:build_test_command_response(
mock_device, 1,
DoorLock.types.DlStatus.FAILURE -- status
),
}
)
test.socket.matter:__expect_send({
mock_device.id,
DoorLock.server.commands.ClearUser(
mock_device, 1,
1
)
})
test.wait_for_events()
test.socket.matter:__queue_receive(
{
mock_device.id,
DoorLock.server.commands.ClearUser:build_test_command_response(
mock_device, 1
),
}
)
test.socket.capability:__expect_send(
mock_device:generate_test_message(
"main",
capabilities.lockUsers.users({}, {visibility={displayed=false}})
)
)
test.socket.capability:__expect_send(
mock_device:generate_test_message(
"main",
capabilities.lockCredentials.credentials({}, {visibility={displayed=false}})
)
)
test.socket.capability:__expect_send(
mock_device:generate_test_message(
"main",
capabilities.lockSchedules.weekDaySchedules({}, {visibility={displayed=false}})
)
)
test.socket.capability:__expect_send(
mock_device:generate_test_message(
"main",
capabilities.lockSchedules.yearDaySchedules({}, {visibility={displayed=false}})
)
)
test.socket.capability:__expect_send(
mock_device:generate_test_message(
"main",
capabilities.lockCredentials.commandResult(
{commandName="addCredential", statusCode="failure", userIndex=1}, {state_change=true, visibility={displayed=false}}
)
)
)
end,
{
min_api_version = 17
}
)

test.run_registered_tests()
Loading