Skip to content

Commit 2e82a85

Browse files
Handling OverallState and OverallTarget from Instance
1 parent 280df4f commit 2e82a85

File tree

2 files changed

+68
-20
lines changed

2 files changed

+68
-20
lines changed

src/app/clusters/closure-control-server/closure-control-server.cpp

+38-16
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,28 @@ CHIP_ERROR Instance::SetMainState(const MainStateEnum & aMainState)
9191
if (mMainState != oldMainState)
9292
{
9393
MatterReportingAttributeChangeCallback(mDelegate.GetEndpointId(), mClusterId, Attributes::MainState::Id);
94-
UpdateCountdownTimeFromClusterLogic();
94+
}
95+
return CHIP_NO_ERROR;
96+
}
97+
98+
CHIP_ERROR Instance::SetOverallState(const DataModel::Nullable<Structs::OverallStateStruct::Type> & aOverallState)
99+
{
100+
DataModel::Nullable<Structs::OverallStateStruct::Type> oldOverallState = mOverallState;
101+
mOverallState = aOverallState;
102+
if (mOverallState != oldOverallState)
103+
{
104+
MatterReportingAttributeChangeCallback(mDelegate.GetEndpointId(), mClusterId, Attributes::OverallState::Id);
105+
}
106+
return CHIP_NO_ERROR;
107+
}
108+
109+
CHIP_ERROR Instance::SetOverallTarget(const DataModel::Nullable<Structs::OverallTargetStruct::Type> & aOverallTarget)
110+
{
111+
DataModel::Nullable<Structs::OverallTargetStruct::Type> oldOverallTarget = mOverallTarget;
112+
mOverallTarget = aOverallTarget;
113+
if (mOverallTarget != oldOverallTarget)
114+
{
115+
MatterReportingAttributeChangeCallback(mDelegate.GetEndpointId(), mClusterId, Attributes::OverallTarget::Id);
95116
}
96117
return CHIP_NO_ERROR;
97118
}
@@ -101,6 +122,16 @@ MainStateEnum Instance::GetMainState() const
101122
return mMainState;
102123
}
103124

125+
DataModel::Nullable<Structs::OverallStateStruct::Type> Instance::GetOverallState() const
126+
{
127+
return mOverallState;
128+
}
129+
130+
DataModel::Nullable<Structs::OverallTargetStruct::Type> Instance::GetOverallTarget() const
131+
{
132+
return mOverallTarget;
133+
}
134+
104135
void Instance::UpdateCountdownTime(bool fromDelegate)
105136
{
106137
app::DataModel::Nullable<uint32_t> newCountdownTime = mDelegate.GetCountdownTime();
@@ -110,20 +141,11 @@ void Instance::UpdateCountdownTime(bool fromDelegate)
110141

111142
if (fromDelegate)
112143
{
113-
// Updates from delegate are reduce-reported to every 10s max (choice of this implementation), in addition
144+
// Updates from delegate are reduce-reported to every 1s max (choice of this implementation), in addition
114145
// to default change-from-null, change-from-zero and increment policy.
115-
auto predicate = [](const decltype(mCountdownTime)::SufficientChangePredicateCandidate & candidate) -> bool {
116-
if (candidate.lastDirtyValue.IsNull() || candidate.newValue.IsNull())
117-
{
118-
return false;
119-
}
120-
121-
uint32_t lastDirtyValue = candidate.lastDirtyValue.Value();
122-
uint32_t newValue = candidate.newValue.Value();
123-
uint32_t kNumSecondsDeltaToReport = 10;
124-
return (newValue < lastDirtyValue) && ((lastDirtyValue - newValue) > kNumSecondsDeltaToReport);
125-
};
126-
markDirty = (mCountdownTime.SetValue(newCountdownTime, now, predicate) == AttributeDirtyState::kMustReport);
146+
System::Clock::Milliseconds64 reportInterval = System::Clock::Milliseconds64(1000);
147+
auto predicate = mCountdownTime.GetPredicateForSufficientTimeSinceLastDirty(reportInterval);
148+
markDirty = (mCountdownTime.SetValue(newCountdownTime, now, predicate) == AttributeDirtyState::kMustReport);
127149
}
128150
else
129151
{
@@ -155,9 +177,9 @@ CHIP_ERROR Instance::Read(const ConcreteReadAttributePath & aPath, AttributeValu
155177
case CurrentErrorList::Id:
156178
return aEncoder.EncodeList([this](const auto & encoder) -> CHIP_ERROR { return this->EncodeCurrentErrorList(encoder); });
157179
case OverallState::Id:
158-
return aEncoder.Encode(mDelegate.GetOverallState());
180+
return aEncoder.Encode(GetOverallState());
159181
case OverallTarget::Id:
160-
return aEncoder.Encode(mDelegate.GetOverallTarget());
182+
return aEncoder.Encode(GetOverallTarget());
161183
case RestingProcedure::Id:
162184
if (HasFeature(Feature::kFallback))
163185
{

src/app/clusters/closure-control-server/closure-control-server.h

+30-4
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ class Delegate
6161
// ------------------------------------------------------------------
6262
// Get attribute methods
6363
virtual DataModel::Nullable<uint32_t> GetCountdownTime() = 0;
64-
virtual DataModel::Nullable<Structs::OverallStateStruct::Type> GetOverallState() = 0;
65-
virtual DataModel::Nullable<Structs::OverallTargetStruct::Type> GetOverallTarget() = 0;
6664
virtual RestingProcedureEnum GetRestingProcedure() = 0;
6765
virtual TriggerConditionEnum GetTriggerCondition() = 0;
6866
virtual TriggerPositionEnum GetTriggerPosition() = 0;
@@ -114,13 +112,39 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface
114112
*/
115113
CHIP_ERROR SetMainState(const MainStateEnum & aMainState);
116114

115+
/**
116+
* Set OverallState.
117+
* @param aMainState The OverallState that should now be the current State.
118+
* @return CHIP_NO_ERROR if set was successful.
119+
*/
120+
CHIP_ERROR SetOverallState(const DataModel::Nullable<Structs::OverallStateStruct::Type> & aOverallState);
121+
122+
/**
123+
* Set OverallTarget.
124+
* @param aMainState The OverallTarget that should be set.
125+
* @return CHIP_NO_ERROR if set was successful.
126+
*/
127+
CHIP_ERROR SetOverallTarget(const DataModel::Nullable<Structs::OverallTargetStruct::Type> & aOverallTarget);
128+
117129
// Attribute getters
118130
/**
119131
* Get Main State.
120132
* @return The Main State.
121133
*/
122134
MainStateEnum GetMainState() const;
123135

136+
/**
137+
* Get OverallState.
138+
* @return The OverallState.
139+
*/
140+
DataModel::Nullable<Structs::OverallStateStruct::Type> GetOverallState() const;
141+
142+
/**
143+
* Get OverallTarget.
144+
* @return The OverallTarget.
145+
*/
146+
DataModel::Nullable<Structs::OverallTargetStruct::Type> GetOverallTarget() const;
147+
124148
/**
125149
* @brief Whenever application delegate wants to possibly report a new updated time,
126150
* call this method. The `GetCountdownTime()` method will be called on the delegate.
@@ -149,11 +173,13 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface
149173
private:
150174
Delegate & mDelegate;
151175
const ClusterId mClusterId;
152-
153176
BitMask<Feature> mFeature;
154177
BitMask<OptionalAttributes> mOptionalAttrs;
155-
MainStateEnum mMainState;
178+
156179
app::QuieterReportingAttribute<uint32_t> mCountdownTime{ DataModel::NullNullable };
180+
MainStateEnum mMainState;
181+
DataModel::Nullable<Structs::OverallStateStruct::Type> & mOverallState;
182+
DataModel::Nullable<Structs::OverallTargetStruct::Type> & mOverallTarget;
157183

158184
// AttributeAccessInterface
159185
CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override;

0 commit comments

Comments
 (0)