Skip to content

Commit 2e0659f

Browse files
committed
Writes the operational state to a persistent storage, so that the state keeps after reboot.
1 parent 1508416 commit 2e0659f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/app/clusters/operational-state-server/operational-state-server.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <app/InteractionModelEngine.h>
2727
#include <app/reporting/reporting.h>
2828
#include <app/util/attribute-storage.h>
29+
#include <app/SafeAttributePersistenceProvider.h>
2930

3031
using namespace chip;
3132
using namespace chip::app;
@@ -59,6 +60,9 @@ CHIP_ERROR Instance::Init()
5960

6061
ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->RegisterCommandHandler(this));
6162

63+
ReturnErrorOnFailure(GetSafeAttributePersistenceProvider()->ReadScalarValue(
64+
ConcreteAttributePath(mEndpointId, mClusterId, Attributes::OperationalState::Id), mOperationalState));
65+
6266
VerifyOrReturnError(registerAttributeAccessOverride(this), CHIP_ERROR_INCORRECT_STATE);
6367

6468
return CHIP_NO_ERROR;
@@ -101,7 +105,10 @@ CHIP_ERROR Instance::SetOperationalState(uint8_t aOpState)
101105
mOperationalState = aOpState;
102106
if (mOperationalState != oldState)
103107
{
104-
MatterReportingAttributeChangeCallback(mEndpointId, mClusterId, Attributes::OperationalState::Id);
108+
// Write new value to persistent storage.
109+
ConcreteAttributePath path = ConcreteAttributePath(mEndpointId, mClusterId, Attributes::OperationalState::Id);
110+
GetSafeAttributePersistenceProvider()->WriteScalarValue(path, mOperationalState);
111+
MatterReportingAttributeChangeCallback(path);
105112
}
106113
return CHIP_NO_ERROR;
107114
}

0 commit comments

Comments
 (0)