From edb8cf4db8f882b2811b5ea05cef582640fcef6e 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..57a418e13b06b5 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(1, &storedValue); + if (status == EMBER_ZCL_STATUS_SUCCESS) + { + // Set actual state to stored before reboot + GetAppTask().GetLightingDevice().InitiateAction(storedValue ? PWMDevice::ON_ACTION : PWMDevice::OFF_ACTION, + AppEvent::kEventType_Lighting, reinterpret_cast(&storedValue)); + } + GetAppTask().UpdateClusterState(); }