Skip to content

Commit d1ac726

Browse files
Fix/cleaup of startUpColorTempCommand
1 parent f9d9f99 commit d1ac726

File tree

1 file changed

+21
-28
lines changed

1 file changed

+21
-28
lines changed

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

+21-28
Original file line numberDiff line numberDiff line change
@@ -2679,39 +2679,32 @@ void ColorControlServer::startUpColorTempCommand(EndpointId endpoint)
26792679

26802680
if (status == Status::Success && !startUpColorTemp.IsNull())
26812681
{
2682-
uint16_t updatedColorTemp = MAX_TEMPERATURE_VALUE;
2683-
status = Attributes::ColorTemperatureMireds::Get(endpoint, &updatedColorTemp);
2682+
uint16_t tempPhysicalMin = MIN_TEMPERATURE_VALUE;
2683+
Attributes::ColorTempPhysicalMinMireds::Get(endpoint, &tempPhysicalMin);
2684+
// Avoid potential divide-by-zero in future Kelvin conversions.
2685+
tempPhysicalMin = std::max(static_cast<uint16_t>(1u), tempPhysicalMin);
26842686

2685-
if (status == Status::Success)
2686-
{
2687-
uint16_t tempPhysicalMin = MIN_TEMPERATURE_VALUE;
2688-
Attributes::ColorTempPhysicalMinMireds::Get(endpoint, &tempPhysicalMin);
2689-
// Avoid potential divide-by-zero in future Kelvin conversions.
2690-
tempPhysicalMin = std::max(static_cast<uint16_t>(1u), tempPhysicalMin);
2687+
uint16_t tempPhysicalMax = MAX_TEMPERATURE_VALUE;
2688+
Attributes::ColorTempPhysicalMaxMireds::Get(endpoint, &tempPhysicalMax);
26912689

2692-
uint16_t tempPhysicalMax = MAX_TEMPERATURE_VALUE;
2693-
Attributes::ColorTempPhysicalMaxMireds::Get(endpoint, &tempPhysicalMax);
2690+
if (tempPhysicalMin <= startUpColorTemp.Value() && startUpColorTemp.Value() <= tempPhysicalMax)
2691+
{
2692+
// Apply valid startup color temp value that is within physical limits of device.
2693+
// Otherwise, the startup value is outside the device's supported range, and the
2694+
// existing setting of ColorTemp attribute will be left unchanged (i.e., treated as
2695+
// if startup color temp was set to null).
2696+
uint16_t epIndex = getEndpointIndex(endpoint);
2697+
MarkAttributeDirty markDirty = SetQuietReportAttribute(quietTemperatureMireds[epIndex], startUpColorTemp.Value(),
2698+
false /* isEndOfTransition */, 0);
2699+
status = Attributes::ColorTemperatureMireds::Set(endpoint, quietTemperatureMireds[epIndex].value().Value(), markDirty);
26942700

2695-
if (tempPhysicalMin <= startUpColorTemp.Value() && startUpColorTemp.Value() <= tempPhysicalMax)
2701+
if (status == Status::Success)
26962702
{
2697-
// Apply valid startup color temp value that is within physical limits of device.
2698-
// Otherwise, the startup value is outside the device's supported range, and the
2699-
// existing setting of ColorTemp attribute will be left unchanged (i.e., treated as
2700-
// if startup color temp was set to null).
2701-
uint16_t epIndex = getEndpointIndex(endpoint);
2702-
MarkAttributeDirty markDirty =
2703-
SetQuietReportAttribute(quietTemperatureMireds[epIndex], updatedColorTemp, false /* isEndOfTransition */, 0);
2704-
status =
2705-
Attributes::ColorTemperatureMireds::Set(endpoint, quietTemperatureMireds[epIndex].value().Value(), markDirty);
2706-
2707-
if (status == Status::Success)
2708-
{
2709-
// Set ColorMode attributes to reflect ColorTemperature.
2710-
auto updateColorMode = ColorModeEnum::kColorTemperatureMireds;
2711-
Attributes::ColorMode::Set(endpoint, updateColorMode);
2703+
// Set ColorMode attributes to reflect ColorTemperature.
2704+
auto updateColorMode = ColorModeEnum::kColorTemperatureMireds;
2705+
Attributes::ColorMode::Set(endpoint, updateColorMode);
27122706

2713-
Attributes::EnhancedColorMode::Set(endpoint, static_cast<EnhancedColorModeEnum>(updateColorMode));
2714-
}
2707+
Attributes::EnhancedColorMode::Set(endpoint, static_cast<EnhancedColorModeEnum>(updateColorMode));
27152708
}
27162709
}
27172710
}

0 commit comments

Comments
 (0)