Skip to content

Commit 56e4d3c

Browse files
Added checks for HasValue in color control apply scene handler
1 parent a621b79 commit 56e4d3c

File tree

1 file changed

+24
-40
lines changed

1 file changed

+24
-40
lines changed

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

+24-40
Original file line numberDiff line numberDiff line change
@@ -237,76 +237,60 @@ class DefaultColorControlSceneHandler : public scenes::DefaultSceneHandlerImpl
237237
case Attributes::CurrentX::Id:
238238
if (SupportsColorMode(endpoint, ColorControl::EnhancedColorMode::kCurrentXAndCurrentY))
239239
{
240-
if (decodePair.valueUnsigned16.HasValue())
241-
colorXTransitionState->finalValue =
242-
std::min(decodePair.valueUnsigned16.Value(), colorXTransitionState->highLimit);
240+
VerifyOrReturnError(decodePair.valueUnsigned16.HasValue(), CHIP_ERROR_INVALID_ARGUMENT);
241+
colorXTransitionState->finalValue =
242+
std::min(decodePair.valueUnsigned16.Value(), colorXTransitionState->highLimit);
243243
}
244244
break;
245245
case Attributes::CurrentY::Id:
246246
if (SupportsColorMode(endpoint, ColorControl::EnhancedColorMode::kCurrentXAndCurrentY))
247247
{
248-
if (decodePair.valueUnsigned16.HasValue())
249-
{
250-
colorYTransitionState->finalValue =
251-
std::min(decodePair.valueUnsigned16.Value(), colorYTransitionState->highLimit);
252-
}
248+
VerifyOrReturnError(decodePair.valueUnsigned16.HasValue(), CHIP_ERROR_INVALID_ARGUMENT);
249+
colorYTransitionState->finalValue =
250+
std::min(decodePair.valueUnsigned16.Value(), colorYTransitionState->highLimit);
253251
}
254252
break;
255253
case Attributes::EnhancedCurrentHue::Id:
256254
if (SupportsColorMode(endpoint, ColorControl::EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation))
257255
{
258-
if (decodePair.valueUnsigned16.HasValue())
259-
{
260-
colorHueTransitionState->finalEnhancedHue = decodePair.valueUnsigned16.Value();
261-
}
256+
VerifyOrReturnError(decodePair.valueUnsigned16.HasValue(), CHIP_ERROR_INVALID_ARGUMENT);
257+
colorHueTransitionState->finalEnhancedHue = decodePair.valueUnsigned16.Value();
262258
}
263259
break;
264260
case Attributes::CurrentSaturation::Id:
265261
if (SupportsColorMode(endpoint, ColorControl::EnhancedColorMode::kCurrentHueAndCurrentSaturation))
266262
{
267-
if (decodePair.valueUnsigned8.HasValue())
268-
{
269-
colorSaturationTransitionState->finalValue = std::min(
270-
static_cast<uint16_t>(decodePair.valueUnsigned8.Value()), colorSaturationTransitionState->highLimit);
271-
}
263+
VerifyOrReturnError(decodePair.valueUnsigned8.HasValue(), CHIP_ERROR_INVALID_ARGUMENT);
264+
colorSaturationTransitionState->finalValue = std::min(static_cast<uint16_t>(decodePair.valueUnsigned8.Value()),
265+
colorSaturationTransitionState->highLimit);
272266
}
273267
break;
274268
case Attributes::ColorLoopActive::Id:
275-
if (decodePair.valueUnsigned8.HasValue())
276-
{
277-
loopActiveValue = decodePair.valueUnsigned8.Value();
278-
}
269+
VerifyOrReturnError(decodePair.valueUnsigned8.HasValue(), CHIP_ERROR_INVALID_ARGUMENT);
270+
loopActiveValue = decodePair.valueUnsigned8.Value();
279271
break;
280272
case Attributes::ColorLoopDirection::Id:
281-
if (decodePair.valueUnsigned8.HasValue())
282-
{
283-
loopDirectionValue = decodePair.valueUnsigned8.Value();
284-
}
273+
VerifyOrReturnError(decodePair.valueUnsigned8.HasValue(), CHIP_ERROR_INVALID_ARGUMENT);
274+
loopDirectionValue = decodePair.valueUnsigned8.Value();
285275
break;
286276
case Attributes::ColorLoopTime::Id:
287-
if (decodePair.valueUnsigned16.HasValue())
288-
{
289-
loopTimeValue = decodePair.valueUnsigned16.Value();
290-
}
277+
VerifyOrReturnError(decodePair.valueUnsigned16.HasValue(), CHIP_ERROR_INVALID_ARGUMENT);
278+
loopTimeValue = decodePair.valueUnsigned16.Value();
291279
break;
292280
case Attributes::ColorTemperatureMireds::Id:
293281
if (SupportsColorMode(endpoint, ColorControl::EnhancedColorMode::kColorTemperature))
294282
{
295-
if (decodePair.valueUnsigned16.HasValue())
296-
{
297-
colorTempTransitionState->finalValue =
298-
std::min(decodePair.valueUnsigned16.Value(), colorTempTransitionState->highLimit);
299-
}
283+
VerifyOrReturnError(decodePair.valueUnsigned16.HasValue(), CHIP_ERROR_INVALID_ARGUMENT);
284+
colorTempTransitionState->finalValue =
285+
std::min(decodePair.valueUnsigned16.Value(), colorTempTransitionState->highLimit);
300286
}
301287
break;
302288
case Attributes::EnhancedColorMode::Id:
303-
if (decodePair.valueUnsigned8.HasValue())
289+
VerifyOrReturnError(decodePair.valueUnsigned8.HasValue(), CHIP_ERROR_INVALID_ARGUMENT);
290+
if (decodePair.valueUnsigned8.Value() <=
291+
static_cast<uint8_t>(ColorControl::EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation))
304292
{
305-
if (decodePair.valueUnsigned8.Value() <=
306-
static_cast<uint8_t>(ColorControl::EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation))
307-
{
308-
targetColorMode = decodePair.valueUnsigned8.Value();
309-
}
293+
targetColorMode = decodePair.valueUnsigned8.Value();
310294
}
311295
break;
312296
default:

0 commit comments

Comments
 (0)