From ab25c70a2a510a038a56cad7b218ebcf049357ad Mon Sep 17 00:00:00 2001 From: Morozov-5F Date: Sat, 28 May 2022 00:29:46 +0300 Subject: [PATCH] [#18677] Set the initial lock state to null - Set the actual lock state from the app without event generation --- .../lock-app/linux/include/LockEndpoint.h | 2 ++ .../door-lock-server/door-lock-server.cpp | 13 ++++++++-- .../door-lock-server/door-lock-server.h | 26 ++++++++++++++++--- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/examples/lock-app/linux/include/LockEndpoint.h b/examples/lock-app/linux/include/LockEndpoint.h index 6654afbdb0278e..503d08fab6679c 100644 --- a/examples/lock-app/linux/include/LockEndpoint.h +++ b/examples/lock-app/linux/include/LockEndpoint.h @@ -57,6 +57,8 @@ class LockEndpoint { lockUser.credentials.reserve(numberOfCredentialsPerUser); } + + DoorLockServer::Instance().SetLockState(endpointId, mLockState); } inline chip::EndpointId GetEndpointId() const { return mEndpointId; } 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 a2272df65c966b..12d919766ce5b2 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.cpp +++ b/src/app/clusters/door-lock-server/door-lock-server.cpp @@ -72,13 +72,22 @@ void DoorLockServer::InitServer(chip::EndpointId endpointId) { emberAfDoorLockClusterPrintln("Door Lock cluster initialized at endpoint #%u", endpointId); - SetLockState(endpointId, DlLockState::kLocked, DlOperationSource::kUnspecified); + auto status = Attributes::LockState::SetNull(endpointId); + if (EMBER_ZCL_STATUS_SUCCESS != status) + { + ChipLogError(Zcl, "[InitDoorLockServer] Unable to set the Lock State attribute to null [status=%d]", status); + } SetActuatorEnabled(endpointId, true); } +bool DoorLockServer::SetLockState(chip::EndpointId endpointId, DlLockState newLockState) +{ + return SetAttribute(endpointId, Attributes::LockState::Id, Attributes::LockState::Set, newLockState); +} + bool DoorLockServer::SetLockState(chip::EndpointId endpointId, DlLockState newLockState, DlOperationSource opSource) { - bool success = SetAttribute(endpointId, Attributes::LockState::Id, Attributes::LockState::Set, newLockState); + bool success = SetLockState(endpointId, newLockState); // Remote operations are handled separately as they use more data unavailable here VerifyOrReturnError(DlOperationSource::kRemote != opSource, success); diff --git a/src/app/clusters/door-lock-server/door-lock-server.h b/src/app/clusters/door-lock-server/door-lock-server.h index c9d84a35aa8d94..8a08cf7c0b2f4a 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.h +++ b/src/app/clusters/door-lock-server/door-lock-server.h @@ -74,7 +74,30 @@ class DoorLockServer void InitServer(chip::EndpointId endpointId); + /** + * Updates the LockState attribute with new value and sends LockOperation event. + * + * @note Does not send an event of opSource is kRemote. + * + * @param endpointId ID of the endpoint to the lock state + * @param newLockState new lock state + * @param opSource source of the operation (will be used in the event). + * + * @return true on success, false on failure. + */ bool SetLockState(chip::EndpointId endpointId, DlLockState newLockState, DlOperationSource opSource); + + /** + * Updates the LockState attribute with new value. + * + * @note Does not generate Lock Operation event + * + * @param endpointId ID of the endpoint to the lock state + * @param newLockState new lock state + * + * @return true on success, false on failure. + */ + bool SetLockState(chip::EndpointId endpointId, DlLockState newLockState); bool SetActuatorEnabled(chip::EndpointId endpointId, bool newActuatorState); bool SetDoorState(chip::EndpointId endpointId, DlDoorState newDoorState); @@ -113,9 +136,6 @@ class DoorLockServer void ClearCredentialCommandHandler(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::ClearCredential::DecodableType & commandData); - void LockUnlockDoorCommandHandler(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - DlLockOperationType operationType, const chip::Optional & pinCode); - void SetWeekDayScheduleCommandHandler( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::SetWeekDaySchedule::DecodableType & commandData);