@@ -2431,12 +2431,12 @@ ColorControlServer::Color16uTransitionState * ColorControlServer::getTempTransit
24312431}
24322432
24332433/* *
2434- * @brief executes move to color temp logic
2434+ * @brief Executes move to color temp logic.
24352435 *
24362436 * @param aEndpoint
24372437 * @param colorTemperature
24382438 * @param transitionTime
2439- * @return Status::Success if successful, Status::UnsupportedEndpoint if the endpoint doesn't support color temperature
2439+ * @return Status::Success if successful, Status::UnsupportedEndpoint if the endpoint doesn't support color temperature.
24402440 */
24412441Status ColorControlServer::moveToColorTemp (EndpointId aEndpoint, uint16_t colorTemperature, uint16_t transitionTime)
24422442{
@@ -2632,49 +2632,28 @@ void ColorControlServer::updateTempCommand(EndpointId endpoint)
26322632}
26332633
26342634/* *
2635- * @brief move color temp command
2636- *
2637- * @param moveMode
2638- * @param rate
2639- * @param colorTemperatureMinimum
2640- * @param colorTemperatureMaximum
2641- * @param optionsMask
2642- * @param optionsOverride
2643- * @return true
2644- * @return false
2635+ * @brief Executes move color temp command.
2636+ * @param endpoint EndpointId of the recipient Color control cluster.
2637+ * @param commandData Struct containing the parameters of the command.
2638+ * @return Status::Success when successful,
2639+ * Status::InvalidCommand when a rate of 0 for a non-stop move or an unknown HueMoveMode is provided
2640+ * Status::UnsupportedEndpoint when the provided endpoint doesn't correspond with a color temp transition state.
26452641 */
2646- bool ColorControlServer::moveColorTempCommand (app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
2647- const Commands::MoveColorTemperature::DecodableType & commandData)
2648- {
2649- auto moveMode = commandData.moveMode ;
2650- uint16_t rate = commandData.rate ;
2651- uint16_t colorTemperatureMinimum = commandData.colorTemperatureMinimumMireds ;
2652- uint16_t colorTemperatureMaximum = commandData.colorTemperatureMaximumMireds ;
2653- BitMask<OptionsBitmap> optionsMask = commandData.optionsMask ;
2654- BitMask<OptionsBitmap> optionsOverride = commandData.optionsOverride ;
2655- EndpointId endpoint = commandPath.mEndpointId ;
2656- Status status = Status::Success;
2657- uint16_t tempPhysicalMin = MIN_TEMPERATURE_VALUE;
2658- uint16_t tempPhysicalMax = MAX_TEMPERATURE_VALUE;
2659- uint16_t transitionTime;
2660-
2661- Color16uTransitionState * colorTempTransitionState = getTempTransitionState (endpoint);
2662- VerifyOrExit (colorTempTransitionState != nullptr , status = Status::UnsupportedEndpoint);
2663-
2642+ Status ColorControlServer::moveColorTempCommand (EndpointId endpoint,
2643+ const Commands::MoveColorTemperature::DecodableType & commandData)
2644+ {
26642645 // check moveMode and rate before any operation is done on the transition states
26652646 // rate value is ignored if the MoveMode is stop
2666- if (moveMode == HueMoveMode::kUnknownEnumValue || (rate == 0 && moveMode != HueMoveMode::kStop ))
2667- {
2668- commandObj->AddStatus (commandPath, Status::InvalidCommand);
2669- return true ;
2670- }
2647+ VerifyOrReturnValue (commandData.moveMode != HueMoveMode::kUnknownEnumValue , Status::InvalidCommand);
2648+ VerifyOrReturnValue ((commandData.rate != 0 || commandData.moveMode == HueMoveMode::kStop ), Status::InvalidCommand);
26712649
2672- if (!shouldExecuteIfOff (endpoint, optionsMask, optionsOverride))
2673- {
2674- commandObj->AddStatus (commandPath, Status::Success);
2675- return true ;
2676- }
2650+ Color16uTransitionState * colorTempTransitionState = getTempTransitionState (endpoint);
2651+ VerifyOrReturnValue (colorTempTransitionState != nullptr , Status::UnsupportedEndpoint);
26772652
2653+ VerifyOrReturnValue (shouldExecuteIfOff (endpoint, commandData.optionsMask , commandData.optionsOverride ), Status::Success);
2654+
2655+ uint16_t tempPhysicalMin = MIN_TEMPERATURE_VALUE;
2656+ uint16_t tempPhysicalMax = MAX_TEMPERATURE_VALUE;
26782657 Attributes::ColorTempPhysicalMinMireds::Get (endpoint, &tempPhysicalMin);
26792658 Attributes::ColorTempPhysicalMaxMireds::Get (endpoint, &tempPhysicalMax);
26802659
@@ -2683,22 +2662,20 @@ bool ColorControlServer::moveColorTempCommand(app::CommandHandler * commandObj,
26832662
26842663 // New command. Need to stop any active transitions.
26852664 stopAllColorTransitions (endpoint);
2686-
2687- if (moveMode == HueMoveMode::kStop )
2688- {
2689- commandObj->AddStatus (commandPath, Status::Success);
2690- return true ;
2691- }
2665+ // For HueMoveMode::kStop we are done here.
2666+ VerifyOrReturnValue (commandData.moveMode != HueMoveMode::kStop , Status::Success);
26922667
26932668 // Per spec, colorTemperatureMinimumMireds field is limited to ColorTempPhysicalMinMireds and
26942669 // when colorTemperatureMinimumMireds field is 0, ColorTempPhysicalMinMireds shall be used (always > 0)
2670+ uint16_t colorTemperatureMinimum = commandData.colorTemperatureMinimumMireds ;
26952671 if (colorTemperatureMinimum < tempPhysicalMin)
26962672 {
26972673 colorTemperatureMinimum = tempPhysicalMin;
26982674 }
26992675
27002676 // Per spec, colorTemperatureMaximumMireds field is limited to ColorTempPhysicalMaxMireds and
27012677 // when colorTemperatureMaximumMireds field is 0, ColorTempPhysicalMaxMireds shall be used
2678+ uint16_t colorTemperatureMaximum = commandData.colorTemperatureMaximumMireds ;
27022679 if ((colorTemperatureMaximum == 0 ) || (colorTemperatureMaximum > tempPhysicalMax))
27032680 {
27042681 colorTemperatureMaximum = tempPhysicalMax;
@@ -2712,7 +2689,7 @@ bool ColorControlServer::moveColorTempCommand(app::CommandHandler * commandObj,
27122689 Attributes::ColorTemperatureMireds::Get (endpoint, &colorTempTransitionState->initialValue );
27132690 colorTempTransitionState->currentValue = colorTempTransitionState->initialValue ;
27142691
2715- if (moveMode == HueMoveMode::kUp )
2692+ if (commandData. moveMode == HueMoveMode::kUp )
27162693 {
27172694 if (tempPhysicalMax > colorTemperatureMaximum)
27182695 {
@@ -2734,7 +2711,8 @@ bool ColorControlServer::moveColorTempCommand(app::CommandHandler * commandObj,
27342711 colorTempTransitionState->finalValue = tempPhysicalMin;
27352712 }
27362713 }
2737- transitionTime = computeTransitionTimeFromStateAndRate (colorTempTransitionState, rate);
2714+
2715+ uint16_t transitionTime = computeTransitionTimeFromStateAndRate (colorTempTransitionState, commandData.rate );
27382716 colorTempTransitionState->stepsRemaining = transitionTime;
27392717 colorTempTransitionState->stepsTotal = transitionTime;
27402718 colorTempTransitionState->timeRemaining = transitionTime;
@@ -2747,63 +2725,54 @@ bool ColorControlServer::moveColorTempCommand(app::CommandHandler * commandObj,
27472725
27482726 // kick off the state machine:
27492727 scheduleTimerCallbackMs (configureTempEventControl (endpoint), TRANSITION_UPDATE_TIME_MS.count ());
2750-
2751- exit:
2752- commandObj->AddStatus (commandPath, status);
2753- return true ;
2728+ return Status::Success;
27542729}
27552730
2756- bool ColorControlServer::moveToColorTempCommand (app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
2757- const Commands::MoveToColorTemperature::DecodableType & commandData)
2731+ /* *
2732+ * @brief Executes move to color temp command.
2733+ * @param endpoint EndpointId of the recipient Color control cluster.
2734+ * @param commandData Struct containing the parameters of the command.
2735+ * @return Status::Success when successful,
2736+ * Status::UnsupportedEndpoint when the provided endpoint doesn't correspond with a color XY transition state (verified in
2737+ * moveToColorTemp function).
2738+ */
2739+ Status ColorControlServer::moveToColorTempCommand (EndpointId endpoint,
2740+ const Commands::MoveToColorTemperature::DecodableType & commandData)
27582741{
2759- if (!shouldExecuteIfOff (commandPath.mEndpointId , commandData.optionsMask , commandData.optionsOverride ))
2760- {
2761- commandObj->AddStatus (commandPath, Status::Success);
2762- return true ;
2763- }
2742+ VerifyOrReturnValue (shouldExecuteIfOff (endpoint, commandData.optionsMask , commandData.optionsOverride ), Status::Success);
27642743
2765- Status status = moveToColorTemp (commandPath. mEndpointId , commandData.colorTemperatureMireds , commandData.transitionTime );
2744+ Status status = moveToColorTemp (endpoint , commandData.colorTemperatureMireds , commandData.transitionTime );
27662745#ifdef MATTER_DM_PLUGIN_SCENES_MANAGEMENT
2767- ScenesManagement::ScenesServer::Instance ().MakeSceneInvalidForAllFabrics (commandPath. mEndpointId );
2746+ ScenesManagement::ScenesServer::Instance ().MakeSceneInvalidForAllFabrics (endpoint );
27682747#endif // MATTER_DM_PLUGIN_SCENES_MANAGEMENT
2769- commandObj->AddStatus (commandPath, status);
2770- return true ;
2748+ return status;
27712749}
27722750
2773- bool ColorControlServer::stepColorTempCommand (app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
2774- const Commands::StepColorTemperature::DecodableType & commandData)
2751+ /* *
2752+ * @brief Executes step color temp command.
2753+ * @param endpoint EndpointId of the recipient Color control cluster.
2754+ * @param commandData Struct containing the parameters of the command
2755+ * @return Status::Success when successful,
2756+ * Status::InvalidCommand when stepSize is 0 or an unknown stepMode is provided
2757+ * Status::UnsupportedEndpoint when the provided endpoint doesn't correspond with a color temp transition state.
2758+ */
2759+ Status ColorControlServer::stepColorTempCommand (EndpointId endpoint,
2760+ const Commands::StepColorTemperature::DecodableType & commandData)
27752761{
2776- auto stepMode = commandData.stepMode ;
2777- uint16_t stepSize = commandData.stepSize ;
2778- uint16_t transitionTime = commandData.transitionTime ;
2779- uint16_t colorTemperatureMinimum = commandData.colorTemperatureMinimumMireds ;
2780- uint16_t colorTemperatureMaximum = commandData.colorTemperatureMaximumMireds ;
2781- BitMask<OptionsBitmap> optionsMask = commandData.optionsMask ;
2782- BitMask<OptionsBitmap> optionsOverride = commandData.optionsOverride ;
2783- EndpointId endpoint = commandPath.mEndpointId ;
2784- Status status = Status::Success;
2785- uint16_t tempPhysicalMin = MIN_TEMPERATURE_VALUE;
2786- uint16_t tempPhysicalMax = MAX_TEMPERATURE_VALUE;
2762+ // Confirm validity of the step mode and step size received
2763+ VerifyOrReturnValue (commandData.stepMode != HueStepMode::kUnknownEnumValue , Status::InvalidCommand);
2764+ VerifyOrReturnValue (commandData.stepSize != 0 , Status::InvalidCommand);
27872765
27882766 Color16uTransitionState * colorTempTransitionState = getTempTransitionState (endpoint);
2789- VerifyOrExit (colorTempTransitionState != nullptr , status = Status::UnsupportedEndpoint);
2767+ VerifyOrReturnValue (colorTempTransitionState != nullptr , Status::UnsupportedEndpoint);
27902768
2791- // Confirm validity of the step mode and step size received
2792- if (stepMode == HueStepMode::kUnknownEnumValue || stepSize == 0 )
2793- {
2794- commandObj->AddStatus (commandPath, Status::InvalidCommand);
2795- return true ;
2796- }
2797-
2798- if (!shouldExecuteIfOff (endpoint, optionsMask, optionsOverride))
2799- {
2800- commandObj->AddStatus (commandPath, Status::Success);
2801- return true ;
2802- }
2769+ VerifyOrReturnValue (shouldExecuteIfOff (endpoint, commandData.optionsMask , commandData.optionsOverride ), Status::Success);
28032770
28042771 // New command. Need to stop any active transitions.
28052772 stopAllColorTransitions (endpoint);
28062773
2774+ uint16_t tempPhysicalMin = MIN_TEMPERATURE_VALUE;
2775+ uint16_t tempPhysicalMax = MAX_TEMPERATURE_VALUE;
28072776 Attributes::ColorTempPhysicalMinMireds::Get (endpoint, &tempPhysicalMin);
28082777 Attributes::ColorTempPhysicalMaxMireds::Get (endpoint, &tempPhysicalMax);
28092778
@@ -2812,13 +2781,15 @@ bool ColorControlServer::stepColorTempCommand(app::CommandHandler * commandObj,
28122781
28132782 // Per spec, colorTemperatureMinimumMireds field is limited to ColorTempPhysicalMinMireds and
28142783 // when colorTemperatureMinimumMireds field is 0, ColorTempPhysicalMinMireds shall be used (always > 0)
2784+ uint16_t colorTemperatureMinimum = commandData.colorTemperatureMinimumMireds ;
28152785 if (colorTemperatureMinimum < tempPhysicalMin)
28162786 {
28172787 colorTemperatureMinimum = tempPhysicalMin;
28182788 }
28192789
28202790 // Per spec, colorTemperatureMaximumMireds field is limited to ColorTempPhysicalMaxMireds and
28212791 // when colorTemperatureMaximumMireds field is 0, ColorTempPhysicalMaxMireds shall be used
2792+ uint16_t colorTemperatureMaximum = commandData.colorTemperatureMaximumMireds ;
28222793 if ((colorTemperatureMaximum == 0 ) || (colorTemperatureMaximum > tempPhysicalMax))
28232794 {
28242795 colorTemperatureMaximum = tempPhysicalMax;
@@ -2834,9 +2805,10 @@ bool ColorControlServer::stepColorTempCommand(app::CommandHandler * commandObj,
28342805
28352806 colorTempTransitionState->currentValue = colorTempTransitionState->initialValue ;
28362807
2837- if (stepMode == HueStepMode::kUp )
2808+ if (commandData. stepMode == HueStepMode::kUp )
28382809 {
2839- uint32_t finalValue32u = static_cast <uint32_t >(colorTempTransitionState->initialValue ) + static_cast <uint32_t >(stepSize);
2810+ uint32_t finalValue32u =
2811+ static_cast <uint32_t >(colorTempTransitionState->initialValue ) + static_cast <uint32_t >(commandData.stepSize );
28402812 if (finalValue32u > UINT16_MAX)
28412813 {
28422814 colorTempTransitionState->finalValue = UINT16_MAX;
@@ -2846,9 +2818,10 @@ bool ColorControlServer::stepColorTempCommand(app::CommandHandler * commandObj,
28462818 colorTempTransitionState->finalValue = static_cast <uint16_t >(finalValue32u);
28472819 }
28482820 }
2849- else if (stepMode == HueStepMode::kDown )
2821+ else if (commandData. stepMode == HueStepMode::kDown )
28502822 {
2851- uint32_t finalValue32u = static_cast <uint32_t >(colorTempTransitionState->initialValue ) - static_cast <uint32_t >(stepSize);
2823+ uint32_t finalValue32u =
2824+ static_cast <uint32_t >(colorTempTransitionState->initialValue ) - static_cast <uint32_t >(commandData.stepSize );
28522825 if (finalValue32u > UINT16_MAX)
28532826 {
28542827 colorTempTransitionState->finalValue = 0 ;
@@ -2858,22 +2831,20 @@ bool ColorControlServer::stepColorTempCommand(app::CommandHandler * commandObj,
28582831 colorTempTransitionState->finalValue = static_cast <uint16_t >(finalValue32u);
28592832 }
28602833 }
2861- colorTempTransitionState->stepsRemaining = std::max<uint16_t >(transitionTime, 1 );
2834+ colorTempTransitionState->stepsRemaining = std::max<uint16_t >(commandData. transitionTime , 1 );
28622835 colorTempTransitionState->stepsTotal = colorTempTransitionState->stepsRemaining ;
2863- colorTempTransitionState->timeRemaining = transitionTime;
2864- colorTempTransitionState->transitionTime = transitionTime;
2836+ colorTempTransitionState->timeRemaining = commandData. transitionTime ;
2837+ colorTempTransitionState->transitionTime = commandData. transitionTime ;
28652838 colorTempTransitionState->endpoint = endpoint;
28662839 colorTempTransitionState->lowLimit = colorTemperatureMinimum;
28672840 colorTempTransitionState->highLimit = colorTemperatureMaximum;
28682841
2869- SetQuietReportRemainingTime (endpoint, transitionTime, true /* isNewTransition */ );
2842+ SetQuietReportRemainingTime (endpoint, commandData. transitionTime , true /* isNewTransition */ );
28702843
28712844 // kick off the state machine:
2872- scheduleTimerCallbackMs (configureTempEventControl (endpoint), transitionTime ? TRANSITION_UPDATE_TIME_MS.count () : 0 );
2873-
2874- exit:
2875- commandObj->AddStatus (commandPath, status);
2876- return true ;
2845+ scheduleTimerCallbackMs (configureTempEventControl (endpoint),
2846+ commandData.transitionTime ? TRANSITION_UPDATE_TIME_MS.count () : 0 );
2847+ return Status::Success;
28772848}
28782849
28792850void ColorControlServer::levelControlColorTempChangeCommand (EndpointId endpoint)
@@ -3220,21 +3191,27 @@ bool emberAfColorControlClusterMoveToColorTemperatureCallback(app::CommandHandle
32203191 const app::ConcreteCommandPath & commandPath,
32213192 const Commands::MoveToColorTemperature::DecodableType & commandData)
32223193{
3223- return ColorControlServer::Instance ().moveToColorTempCommand (commandObj, commandPath, commandData);
3194+ Status status = ColorControlServer::Instance ().moveToColorTempCommand (commandPath.mEndpointId , commandData);
3195+ commandObj->AddStatus (commandPath, status);
3196+ return true ;
32243197}
32253198
32263199bool emberAfColorControlClusterMoveColorTemperatureCallback (app::CommandHandler * commandObj,
32273200 const app::ConcreteCommandPath & commandPath,
32283201 const Commands::MoveColorTemperature::DecodableType & commandData)
32293202{
3230- return ColorControlServer::Instance ().moveColorTempCommand (commandObj, commandPath, commandData);
3203+ Status status = ColorControlServer::Instance ().moveColorTempCommand (commandPath.mEndpointId , commandData);
3204+ commandObj->AddStatus (commandPath, status);
3205+ return true ;
32313206}
32323207
32333208bool emberAfColorControlClusterStepColorTemperatureCallback (app::CommandHandler * commandObj,
32343209 const app::ConcreteCommandPath & commandPath,
32353210 const Commands::StepColorTemperature::DecodableType & commandData)
32363211{
3237- return ColorControlServer::Instance ().stepColorTempCommand (commandObj, commandPath, commandData);
3212+ Status status = ColorControlServer::Instance ().stepColorTempCommand (commandPath.mEndpointId , commandData);
3213+ commandObj->AddStatus (commandPath, status);
3214+ return true ;
32383215}
32393216
32403217void emberAfPluginLevelControlCoupledColorTempChangeCallback (EndpointId endpoint)
0 commit comments