Skip to content

Commit 9134168

Browse files
authored
Merge pull request #3354 from SmartThingsCommunity/zigbee-lock/do-not-create-on-update
zigbee lock: do not add user if update user is called
2 parents a3a554d + 7e3f8eb commit 9134168

2 files changed

Lines changed: 7 additions & 26 deletions

File tree

‎drivers/SmartThings/zigbee-lock/src/lock_handlers/capabilities.lua‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,10 @@ function CapabilityHandlers.update_user(driver, device, command)
6464
return
6565
end
6666

67-
local result_status
68-
if not tables.find_entry(device, "users", command.args.userIndex) then
69-
result_status = tables.add_entry(device, "users", {
70-
userIndex = command.args.userIndex,
71-
userName = command.args.userName,
72-
userType = command.args.userType,
73-
})
74-
else
75-
result_status = tables.update_entry(device, "users",
76-
command.args.userIndex,
77-
{ userName = command.args.userName, userType = command.args.userType }
78-
)
79-
end
67+
local result_status = tables.update_entry(device, "users",
68+
command.args.userIndex,
69+
{ userName = command.args.userName, userType = command.args.userType }
70+
)
8071

8172
local additional_info = result_status == consts.COMMAND_RESULT.SUCCESS and { userIndex = command.args.userIndex }
8273
lock_utils.emit_command_result(device, capabilities.lockUsers, consts.LOCK_USERS.UPDATE, result_status, additional_info)

‎drivers/SmartThings/zigbee-lock/src/test/test_lock_users_commands.lua‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -199,28 +199,18 @@ test.register_coroutine_test(
199199
)
200200

201201
test.register_coroutine_test(
202-
"updateUser: adds user and returns success when the target userIndex does not exist",
202+
"updateUser: does not create a user and returns failure when the target userIndex does not exist",
203203
function()
204-
-- empty table, add user
204+
-- empty table: updateUser must not add a user
205205
test.socket.capability:__queue_receive({
206206
mock_device.id,
207207
{ capability = capabilities.lockUsers.ID, command = "updateUser", args = { 99, "Ghost", "guest" } },
208208
})
209209

210-
test.socket.capability:__expect_send(
211-
mock_device:generate_test_message("main",
212-
capabilities.lockUsers.users(
213-
{
214-
{ userIndex = 99, userName = "Ghost", userType = "guest" },
215-
},
216-
{ visibility = { displayed = false } }
217-
))
218-
)
219-
220210
test.socket.capability:__expect_send(
221211
mock_device:generate_test_message("main",
222212
capabilities.lockUsers.commandResult(
223-
{ commandName = "updateUser", statusCode = "success", userIndex = 99 },
213+
{ commandName = "updateUser", statusCode = "failure" },
224214
{ state_change = true, visibility = { displayed = false } }
225215
))
226216
)

0 commit comments

Comments
 (0)