From d716bfb8e15acd1ef17f938cd70109202a7875d7 Mon Sep 17 00:00:00 2001 From: Kamil Kasperczyk <66371704+kkasperczyk-no@users.noreply.github.com> Date: Fri, 2 Sep 2022 16:12:56 +0200 Subject: [PATCH] [nrfconnect] Fixed handling lock/unlock door lock commands (#22359) Some time ago setting lock state attribute was removed from the door lock cluster code, so basically now it doesn't work in nrfconnect example, as application was relying on the cluster code. Added handling attribute state in the application. --- examples/lock-app/nrfconnect/main/AppTask.cpp | 5 +---- .../lock-app/nrfconnect/main/ZclCallbacks.cpp | 20 +++++++++++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/examples/lock-app/nrfconnect/main/AppTask.cpp b/examples/lock-app/nrfconnect/main/AppTask.cpp index 9b21708f7d5038..1ba1bd52fcdaef 100644 --- a/examples/lock-app/nrfconnect/main/AppTask.cpp +++ b/examples/lock-app/nrfconnect/main/AppTask.cpp @@ -504,10 +504,7 @@ void AppTask::LockStateChanged(BoltLockManager::State state, BoltLockManager::Op break; } - if (source != BoltLockManager::OperationSource::kRemote) - { - sAppTask.UpdateClusterState(state, source); - } + sAppTask.UpdateClusterState(state, source); } void AppTask::PostEvent(AppEvent * aEvent) diff --git a/examples/lock-app/nrfconnect/main/ZclCallbacks.cpp b/examples/lock-app/nrfconnect/main/ZclCallbacks.cpp index ccb5526344f05c..3b737aa2b472f6 100644 --- a/examples/lock-app/nrfconnect/main/ZclCallbacks.cpp +++ b/examples/lock-app/nrfconnect/main/ZclCallbacks.cpp @@ -77,12 +77,28 @@ bool emberAfPluginDoorLockSetCredential(EndpointId endpointId, uint16_t credenti bool emberAfPluginDoorLockOnDoorLockCommand(EndpointId endpointId, const Optional & pinCode, DlOperationError & err) { - return BoltLockMgr().ValidatePIN(pinCode, err); + bool result = BoltLockMgr().ValidatePIN(pinCode, err); + + /* Handle changing attribute state on command reception */ + if (result) + { + BoltLockMgr().Lock(BoltLockManager::OperationSource::kRemote); + } + + return result; } bool emberAfPluginDoorLockOnDoorUnlockCommand(EndpointId endpointId, const Optional & pinCode, DlOperationError & err) { - return BoltLockMgr().ValidatePIN(pinCode, err); + bool result = BoltLockMgr().ValidatePIN(pinCode, err); + + /* Handle changing attribute state on command reception */ + if (result) + { + BoltLockMgr().Unlock(BoltLockManager::OperationSource::kRemote); + } + + return result; } void emberAfDoorLockClusterInitCallback(EndpointId endpoint)