diff --git a/src/app/clusters/door-lock-server/door-lock-server.cpp b/src/app/clusters/door-lock-server/door-lock-server.cpp index 884f7c38cfd1f5..655c0fb89b7c0a 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.cpp +++ b/src/app/clusters/door-lock-server/door-lock-server.cpp @@ -2899,23 +2899,37 @@ EmberAfStatus DoorLockServer::clearCredentials(chip::EndpointId endpointId, chip return EMBER_ZCL_STATUS_FAILURE; } + EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; + bool clearedCredential = false; for (uint16_t i = 1; i < maxNumberOfCredentials; ++i) { - auto status = clearCredential(endpointId, modifier, sourceNodeId, credentialType, i, false); - if (EMBER_ZCL_STATUS_SUCCESS != status) + EmberAfStatus clearStatus = clearCredential(endpointId, modifier, sourceNodeId, credentialType, i, false); + if (EMBER_ZCL_STATUS_SUCCESS != clearStatus) { ChipLogError(Zcl, "[clearCredentials] Unable to clear the credential - internal error " "[endpointId=%d,credentialType=%u,credentialIndex=%d,status=%d]", endpointId, to_underlying(credentialType), i, status); - return status; + if (status == EMBER_ZCL_STATUS_SUCCESS) + { + status = clearStatus; + } + } + else + { + clearedCredential = true; } } - sendRemoteLockUserChange(endpointId, credentialTypeToLockDataType(credentialType), DataOperationTypeEnum::kClear, sourceNodeId, - modifier, 0xFFFE, 0xFFFE); + // Generate the event if we cleared any credentials, even if we then had errors + // clearing other ones, so we don't have credentials silently disappearing. + if (clearedCredential) + { + sendRemoteLockUserChange(endpointId, credentialTypeToLockDataType(credentialType), DataOperationTypeEnum::kClear, + sourceNodeId, modifier, 0xFFFE, 0xFFFE); + } - return EMBER_ZCL_STATUS_SUCCESS; + return status; } bool DoorLockServer::clearFabricFromCredentials(chip::EndpointId endpointId, CredentialTypeEnum credentialType,