From 2743505d2dd2d3678890f03f865c85366a88086a Mon Sep 17 00:00:00 2001 From: Michael Rupp <95718139+mykrupp@users.noreply.github.com> Date: Mon, 14 Aug 2023 10:11:08 -0400 Subject: [PATCH] [Silabs] Update lock app to send correct lock operation event (#28660) * fix lock operation event * remove MakeNullable include * Restyled by clang-format --------- Co-authored-by: Restyled.io --- .../lock-app/silabs/include/LockManager.h | 12 ++++++---- examples/lock-app/silabs/src/AppTask.cpp | 4 +--- examples/lock-app/silabs/src/LockManager.cpp | 24 ++++++++++++------- examples/lock-app/silabs/src/ZclCallbacks.cpp | 6 ++--- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/examples/lock-app/silabs/include/LockManager.h b/examples/lock-app/silabs/include/LockManager.h index 901dfdbd06cb04..9adcc863f0aec7 100644 --- a/examples/lock-app/silabs/include/LockManager.h +++ b/examples/lock-app/silabs/include/LockManager.h @@ -143,9 +143,12 @@ class LockManager typedef void (*Callback_fn_completed)(Action_t); void SetCallbacks(Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB); - bool Lock(chip::EndpointId endpointId, const Optional & pin, OperationErrorEnum & err); - bool Unlock(chip::EndpointId endpointId, const Optional & pin, OperationErrorEnum & err); - bool Unbolt(chip::EndpointId endpointId, const Optional & pin, OperationErrorEnum & err); + bool Lock(chip::EndpointId endpointId, const Nullable & fabricIdx, const Nullable & nodeId, + const Optional & pin, OperationErrorEnum & err); + bool Unlock(chip::EndpointId endpointId, const Nullable & fabricIdx, const Nullable & nodeId, + const Optional & pin, OperationErrorEnum & err); + bool Unbolt(chip::EndpointId endpointId, const Nullable & fabricIdx, const Nullable & nodeId, + const Optional & pin, OperationErrorEnum & err); bool GetUser(chip::EndpointId endpointId, uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user); bool SetUser(chip::EndpointId endpointId, uint16_t userIndex, chip::FabricIndex creator, chip::FabricIndex modifier, @@ -183,7 +186,8 @@ class LockManager bool IsValidYeardayScheduleIndex(uint8_t scheduleIndex); bool IsValidHolidayScheduleIndex(uint8_t scheduleIndex); - bool setLockState(chip::EndpointId endpointId, DlLockState lockState, const Optional & pin, + bool setLockState(chip::EndpointId endpointId, const Nullable & fabricIdx, + const Nullable & nodeId, DlLockState lockState, const Optional & pin, OperationErrorEnum & err); const char * lockStateToString(DlLockState lockState) const; diff --git a/examples/lock-app/silabs/src/AppTask.cpp b/examples/lock-app/silabs/src/AppTask.cpp index 8afe7d6cc8d9e5..7d86fec80a07d9 100644 --- a/examples/lock-app/silabs/src/AppTask.cpp +++ b/examples/lock-app/silabs/src/AppTask.cpp @@ -352,11 +352,9 @@ void AppTask::UpdateClusterState(intptr_t context) bool unlocked = LockMgr().NextState(); DlLockState newState = unlocked ? DlLockState::kUnlocked : DlLockState::kLocked; - OperationSourceEnum source = OperationSourceEnum::kUnspecified; - // write the new lock value EmberAfStatus status = - DoorLockServer::Instance().SetLockState(1, newState, source) ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE; + DoorLockServer::Instance().SetLockState(1, newState) ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE; if (status != EMBER_ZCL_STATUS_SUCCESS) { diff --git a/examples/lock-app/silabs/src/LockManager.cpp b/examples/lock-app/silabs/src/LockManager.cpp index f3c6dfe748ca35..8190dbddd6141e 100644 --- a/examples/lock-app/silabs/src/LockManager.cpp +++ b/examples/lock-app/silabs/src/LockManager.cpp @@ -288,19 +288,22 @@ void LockManager::ActuatorMovementTimerEventHandler(AppEvent * aEvent) } } -bool LockManager::Lock(chip::EndpointId endpointId, const Optional & pin, OperationErrorEnum & err) +bool LockManager::Lock(chip::EndpointId endpointId, const Nullable & fabricIdx, + const Nullable & nodeId, const Optional & pin, OperationErrorEnum & err) { - return setLockState(endpointId, DlLockState::kLocked, pin, err); + return setLockState(endpointId, fabricIdx, nodeId, DlLockState::kLocked, pin, err); } -bool LockManager::Unlock(chip::EndpointId endpointId, const Optional & pin, OperationErrorEnum & err) +bool LockManager::Unlock(chip::EndpointId endpointId, const Nullable & fabricIdx, + const Nullable & nodeId, const Optional & pin, OperationErrorEnum & err) { - return setLockState(endpointId, DlLockState::kUnlocked, pin, err); + return setLockState(endpointId, fabricIdx, nodeId, DlLockState::kUnlocked, pin, err); } -bool LockManager::Unbolt(chip::EndpointId endpointId, const Optional & pin, OperationErrorEnum & err) +bool LockManager::Unbolt(chip::EndpointId endpointId, const Nullable & fabricIdx, + const Nullable & nodeId, const Optional & pin, OperationErrorEnum & err) { - return setLockState(endpointId, DlLockState::kUnlocked, pin, err); + return setLockState(endpointId, fabricIdx, nodeId, DlLockState::kUnlocked, pin, err); } bool LockManager::GetUser(chip::EndpointId endpointId, uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user) @@ -664,7 +667,8 @@ const char * LockManager::lockStateToString(DlLockState lockState) const return "Unknown"; } -bool LockManager::setLockState(chip::EndpointId endpointId, DlLockState lockState, const Optional & pin, +bool LockManager::setLockState(chip::EndpointId endpointId, const Nullable & fabricIdx, + const Nullable & nodeId, DlLockState lockState, const Optional & pin, OperationErrorEnum & err) { @@ -683,7 +687,8 @@ bool LockManager::setLockState(chip::EndpointId endpointId, DlLockState lockStat ChipLogDetail(Zcl, "Door Lock App: setting door lock state to \"%s\" [endpointId=%d]", lockStateToString(lockState), endpointId); - DoorLockServer::Instance().SetLockState(endpointId, lockState); + DoorLockServer::Instance().SetLockState(endpointId, lockState, OperationSourceEnum::kRemote, NullNullable, NullNullable, + fabricIdx, nodeId); return true; } @@ -708,7 +713,8 @@ bool LockManager::setLockState(chip::EndpointId endpointId, DlLockState lockStat "Lock App: specified PIN code was found in the database, setting lock state to \"%s\" [endpointId=%d]", lockStateToString(lockState), endpointId); - DoorLockServer::Instance().SetLockState(endpointId, lockState); + DoorLockServer::Instance().SetLockState(endpointId, lockState, OperationSourceEnum::kRemote, NullNullable, NullNullable, + fabricIdx, nodeId); return true; } diff --git a/examples/lock-app/silabs/src/ZclCallbacks.cpp b/examples/lock-app/silabs/src/ZclCallbacks.cpp index dc5d60915218ae..12649100df5737 100644 --- a/examples/lock-app/silabs/src/ZclCallbacks.cpp +++ b/examples/lock-app/silabs/src/ZclCallbacks.cpp @@ -66,7 +66,7 @@ bool emberAfPluginDoorLockOnDoorLockCommand(chip::EndpointId endpointId, const N OperationErrorEnum & err) { ChipLogProgress(Zcl, "Door Lock App: Lock Command endpoint=%d", endpointId); - bool status = LockMgr().Lock(endpointId, pinCode, err); + bool status = LockMgr().Lock(endpointId, fabricIdx, nodeId, pinCode, err); if (status == true) { LockMgr().InitiateAction(AppEvent::kEventType_Lock, LockManager::LOCK_ACTION); @@ -79,7 +79,7 @@ bool emberAfPluginDoorLockOnDoorUnlockCommand(chip::EndpointId endpointId, const OperationErrorEnum & err) { ChipLogProgress(Zcl, "Door Lock App: Unlock Command endpoint=%d", endpointId); - bool status = LockMgr().Unlock(endpointId, pinCode, err); + bool status = LockMgr().Unlock(endpointId, fabricIdx, nodeId, pinCode, err); if (status == true) { LockMgr().InitiateAction(AppEvent::kEventType_Lock, LockManager::UNLOCK_ACTION); @@ -93,7 +93,7 @@ bool emberAfPluginDoorLockOnDoorUnboltCommand(chip::EndpointId endpointId, const OperationErrorEnum & err) { ChipLogProgress(Zcl, "Door Lock App: Unbolt Command endpoint=%d", endpointId); - bool status = LockMgr().Unlock(endpointId, pinCode, err); + bool status = LockMgr().Unlock(endpointId, fabricIdx, nodeId, pinCode, err); if (status == true) { LockMgr().InitiateAction(AppEvent::kEventType_Lock, LockManager::UNLOCK_ACTION);