From 9d0b1cf32ced3ee9102f37439d7622a91b9b0a4c Mon Sep 17 00:00:00 2001 From: Kamil Kasperczyk Date: Wed, 21 Sep 2022 15:23:42 +0200 Subject: [PATCH] [nrfconnect] Added reading stored onoff state in lighting app OnOff cluster state is not read on lighting-app init, so the state stored before reboot is not recovered. --- .../lighting-app/nrfconnect/main/ZclCallbacks.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/examples/lighting-app/nrfconnect/main/ZclCallbacks.cpp b/examples/lighting-app/nrfconnect/main/ZclCallbacks.cpp index fa4798c678fff2..024d70a33f60f0 100644 --- a/examples/lighting-app/nrfconnect/main/ZclCallbacks.cpp +++ b/examples/lighting-app/nrfconnect/main/ZclCallbacks.cpp @@ -19,6 +19,7 @@ #include "AppTask.h" #include "PWMDevice.h" +#include #include #include #include @@ -26,6 +27,7 @@ using namespace chip; using namespace chip::app::Clusters; +using namespace chip::app::Clusters::OnOff; void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size, uint8_t * value) @@ -70,5 +72,17 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & */ void emberAfOnOffClusterInitCallback(EndpointId endpoint) { + EmberAfStatus status; + bool storedValue; + + // Read storedValue on/off value + status = Attributes::OnOff::Get(endpoint, &storedValue); + if (status == EMBER_ZCL_STATUS_SUCCESS) + { + // Set actual state to the cluster state that was last persisted + GetAppTask().GetLightingDevice().InitiateAction(storedValue ? PWMDevice::ON_ACTION : PWMDevice::OFF_ACTION, + AppEvent::kEventType_Lighting, reinterpret_cast(&storedValue)); + } + GetAppTask().UpdateClusterState(); }