@@ -36,9 +36,9 @@ function ZigbeeHandlers.set_pin_code_response(driver, device, zb_rx)
3636 }
3737
3838 -- apply result based on response and identify command result status
39- local result_status
39+ local result_status , user_index
4040 if set_pin_code_status == SetCodeStatus .SUCCESS then
41- result_status = lock_utils .add_commanded_credential (device , command_in_progress , credential_args_in_use )
41+ result_status , user_index = lock_utils .add_commanded_credential (device , command_in_progress , credential_args_in_use )
4242 elseif RESPONSE_RESULT_MAP [set_pin_code_status ] then
4343 result_status = RESPONSE_RESULT_MAP [set_pin_code_status ]
4444 else
@@ -48,7 +48,7 @@ function ZigbeeHandlers.set_pin_code_response(driver, device, zb_rx)
4848 -- emit command result
4949 if command_in_progress then
5050 local additional_info = result_status == consts .COMMAND_RESULT .SUCCESS and {
51- userIndex = credential_args_in_use . userIndex ,
51+ userIndex = user_index ,
5252 credentialIndex = credential_args_in_use .credentialIndex ,
5353 } or nil
5454 lock_utils .emit_command_result (device , capabilities .lockCredentials , command_in_progress , result_status , additional_info )
@@ -198,8 +198,9 @@ function ZigbeeHandlers.programming_event_notification(driver, device, zb_rx)
198198 local credential_args_in_use = device :get_field (consts .DRIVER_STATE .CREDENTIAL_ARGS_IN_USE ) or {}
199199 if command_in_progress and credential_args_in_use .credentialIndex == user_id then
200200 local result_status
201+ local user_index = credential_args_in_use .userIndex
201202 if event_code == ProgramEventCode .PIN_CODE_ADDED then -- note: some devices emit PIN_CODE_ADDED even for UPDATE events
202- result_status = lock_utils .add_commanded_credential (device , command_in_progress , credential_args_in_use )
203+ result_status , user_index = lock_utils .add_commanded_credential (device , command_in_progress , credential_args_in_use )
203204 elseif event_code == ProgramEventCode .PIN_CODE_DELETED and (command_in_progress == consts .LOCK_CREDENTIALS .DELETE or command_in_progress == consts .LOCK_USERS .DELETE ) then
204205 result_status = tables .delete_entry (device , " credentials" , credential_args_in_use .credentialIndex )
205206 -- the deleteUser command injects a deleteCredential command, so ensure the lockUsers command results is emitted in this case.
@@ -220,7 +221,7 @@ function ZigbeeHandlers.programming_event_notification(driver, device, zb_rx)
220221 capabilities .lockCredentials ,
221222 command_in_progress ,
222223 result_status ,
223- { userIndex = credential_args_in_use . userIndex , credentialIndex = credential_args_in_use .credentialIndex }
224+ { userIndex = user_index , credentialIndex = credential_args_in_use .credentialIndex }
224225 )
225226 lock_utils .clear_busy_state (device )
226227 return
0 commit comments