Skip to content

Commit

Permalink
[nrfconnect] Added reading stored onoff state in lighting app (#22791)
Browse files Browse the repository at this point in the history
OnOff cluster state is not read on lighting-app init, so the state
stored before reboot is not recovered.
  • Loading branch information
kkasperczyk-no authored and pull[bot] committed Nov 17, 2022
1 parent c43216d commit 2313024
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions examples/lighting-app/nrfconnect/main/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
#include "AppTask.h"
#include "PWMDevice.h"

#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/ConcreteAttributePath.h>
#include <lib/support/logging/CHIPLogging.h>

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)
Expand Down Expand Up @@ -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<uint8_t *>(&storedValue));
}

GetAppTask().UpdateClusterState();
}

0 comments on commit 2313024

Please sign in to comment.