Skip to content

Commit e2dc005

Browse files
j-ororkececille
andauthored
[Fix][Valve] Move DefaultOpenDuration constraint handling out of IDM_9_1 test module PR (project-chip#43715)
* [Fix][Valve] Move DefaultOpenDuration constraint handling out of IDM_9_1 test module PR * Fix DefaultOpenDuration nullable persistence encoding --------- Co-authored-by: C Freeman <cecille@google.com>
1 parent 9d46b0c commit e2dc005

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

src/app/clusters/valve-configuration-and-control-server/ValveConfigurationAndControlCluster.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,25 @@ DataModel::ActionReturnStatus ValveConfigurationAndControlCluster::WriteImpl(con
153153

154154
if (request.path.mAttributeId == ValveConfigurationAndControl::Attributes::DefaultOpenDuration::Id)
155155
{
156-
AttributePersistence persistence{ mContext->attributeStorage };
157-
return persistence.DecodeAndStoreNativeEndianValue(request.path, decoder, mDefaultOpenDuration);
156+
DataModel::Nullable<uint32_t> value;
157+
ReturnErrorOnFailure(decoder.Decode(value));
158+
159+
// DefaultOpenDuration has a constraint: min value = 1 (when not null)
160+
if (!value.IsNull() && value.Value() < 1)
161+
{
162+
return CHIP_IM_GLOBAL_STATUS(ConstraintError);
163+
}
164+
165+
// Avoid rewriting storage if unchanged
166+
VerifyOrReturnValue(value != mDefaultOpenDuration, DataModel::ActionReturnStatus::FixedStatus::kWriteSuccessNoOp);
167+
168+
mDefaultOpenDuration = value;
169+
170+
// Persist using AttributePersistence nullable storage representation.
171+
NumericAttributeTraits<uint32_t>::StorageType storageValue;
172+
NullableToStorage(mDefaultOpenDuration, storageValue);
173+
return mContext->attributeStorage.WriteValue(request.path,
174+
{ reinterpret_cast<const uint8_t *>(&storageValue), sizeof(storageValue) });
158175
}
159176

160177
if (request.path.mAttributeId == ValveConfigurationAndControl::Attributes::DefaultOpenLevel::Id)

0 commit comments

Comments
 (0)