@@ -38,16 +38,16 @@ namespace {
38
38
* @return true If the preset is valid i.e the PresetHandle (if not null) fits within size constraints and the presetScenario enum
39
39
* value is valid. Otherwise, return false.
40
40
*/
41
- bool IsValidPresetEntry (const PresetStruct::Type & preset)
41
+ bool IsValidPresetEntry (const PresetStructWithOwnedMembers & preset)
42
42
{
43
43
// Check that the preset handle is not too long.
44
- if (!preset.presetHandle .IsNull () && preset.presetHandle .Value ().size () > kPresetHandleSize )
44
+ if (!preset.GetPresetHandle () .IsNull () && preset.GetPresetHandle () .Value ().size () > kPresetHandleSize )
45
45
{
46
46
return false ;
47
47
}
48
48
49
49
// Ensure we have a valid PresetScenario.
50
- return (preset.presetScenario != PresetScenarioEnum::kUnknownEnumValue );
50
+ return (preset.GetPresetScenario () != PresetScenarioEnum::kUnknownEnumValue );
51
51
}
52
52
53
53
/* *
@@ -123,7 +123,7 @@ bool MatchingPendingPresetExists(Delegate * delegate, const PresetStructWithOwne
123
123
*
124
124
* @return true if a matching entry was found in the presets attribute list, false otherwise.
125
125
*/
126
- bool GetMatchingPresetInPresets (Delegate * delegate, const PresetStruct::Type & presetToMatch ,
126
+ bool GetMatchingPresetInPresets (Delegate * delegate, const DataModel::Nullable<ByteSpan> & presetHandle ,
127
127
PresetStructWithOwnedMembers & matchingPreset)
128
128
{
129
129
VerifyOrReturnValue (delegate != nullptr , false );
@@ -143,7 +143,7 @@ bool GetMatchingPresetInPresets(Delegate * delegate, const PresetStruct::Type &
143
143
}
144
144
145
145
// Note: presets coming from our delegate always have a handle.
146
- if (presetToMatch. presetHandle .Value ().data_equal (matchingPreset.GetPresetHandle ().Value ()))
146
+ if (presetHandle.Value ().data_equal (matchingPreset.GetPresetHandle ().Value ()))
147
147
{
148
148
return true ;
149
149
}
@@ -351,14 +351,15 @@ Status ThermostatAttrAccess::SetActivePreset(EndpointId endpoint, DataModel::Nul
351
351
return Status::Success;
352
352
}
353
353
354
- CHIP_ERROR ThermostatAttrAccess::AppendPendingPreset (Thermostat::Delegate * delegate, const PresetStruct::Type & preset )
354
+ CHIP_ERROR ThermostatAttrAccess::AppendPendingPreset (Thermostat::Delegate * delegate, const PresetStruct::Type & newPreset )
355
355
{
356
+ PresetStructWithOwnedMembers preset = newPreset;
356
357
if (!IsValidPresetEntry (preset))
357
358
{
358
359
return CHIP_IM_GLOBAL_STATUS (ConstraintError);
359
360
}
360
361
361
- if (preset.presetHandle .IsNull ())
362
+ if (preset.GetPresetHandle () .IsNull ())
362
363
{
363
364
if (IsBuiltIn (preset))
364
365
{
@@ -367,37 +368,56 @@ CHIP_ERROR ThermostatAttrAccess::AppendPendingPreset(Thermostat::Delegate * dele
367
368
}
368
369
else
369
370
{
370
- auto & presetHandle = preset.presetHandle .Value ();
371
371
372
372
// Per spec we need to check that:
373
373
// (a) There is an existing non-pending preset with this handle.
374
374
PresetStructWithOwnedMembers matchingPreset;
375
- if (!GetMatchingPresetInPresets (delegate, preset, matchingPreset))
375
+ if (!GetMatchingPresetInPresets (delegate, preset. GetPresetHandle (). Value () , matchingPreset))
376
376
{
377
377
return CHIP_IM_GLOBAL_STATUS (NotFound);
378
378
}
379
379
380
380
// (b) There is no existing pending preset with this handle.
381
- if (CountPresetsInPendingListWithPresetHandle (delegate, presetHandle ) > 0 )
381
+ if (CountPresetsInPendingListWithPresetHandle (delegate, preset. GetPresetHandle (). Value () ) > 0 )
382
382
{
383
383
return CHIP_IM_GLOBAL_STATUS (ConstraintError);
384
384
}
385
385
386
+ const auto & presetBuiltIn = preset.GetBuiltIn ();
387
+ const auto & matchingPresetBuiltIn = matchingPreset.GetBuiltIn ();
386
388
// (c)/(d) The built-in fields do not have a mismatch.
387
- // TODO: What's the story with nullability on the BuiltIn field?
388
- if (!preset.builtIn .IsNull () && !matchingPreset.GetBuiltIn ().IsNull () &&
389
- preset.builtIn .Value () != matchingPreset.GetBuiltIn ().Value ())
389
+ if (presetBuiltIn.IsNull ())
390
390
{
391
- return CHIP_IM_GLOBAL_STATUS (ConstraintError);
391
+ if (matchingPresetBuiltIn.IsNull ())
392
+ {
393
+ // This really shouldn't happen; internal presets should alway have built-in set
394
+ return CHIP_IM_GLOBAL_STATUS (InvalidInState);
395
+ }
396
+ else
397
+ {
398
+ preset.SetBuiltIn (matchingPresetBuiltIn.Value ());
399
+ }
400
+ }
401
+ else
402
+ {
403
+ if (matchingPresetBuiltIn.IsNull ())
404
+ {
405
+ // This really shouldn't happen; internal presets should alway have built-in set
406
+ return CHIP_IM_GLOBAL_STATUS (InvalidInState);
407
+ }
408
+ if (presetBuiltIn.Value () != matchingPresetBuiltIn.Value ())
409
+ {
410
+ return CHIP_IM_GLOBAL_STATUS (ConstraintError);
411
+ }
392
412
}
393
413
}
394
414
395
- if (!PresetScenarioExistsInPresetTypes (delegate, preset.presetScenario ))
415
+ if (!PresetScenarioExistsInPresetTypes (delegate, preset.GetPresetScenario () ))
396
416
{
397
417
return CHIP_IM_GLOBAL_STATUS (ConstraintError);
398
418
}
399
419
400
- if (preset.name .HasValue () && !PresetTypeSupportsNames (delegate, preset.presetScenario ))
420
+ if (preset.GetName () .HasValue () && !PresetTypeSupportsNames (delegate, preset.GetPresetScenario () ))
401
421
{
402
422
return CHIP_IM_GLOBAL_STATUS (ConstraintError);
403
423
}
0 commit comments