mirror of
https://github.com/esphome/esphome.git
synced 2024-11-26 08:55:22 +01:00
Fix issue when setting cw/ww brightness via temperature (#5976)
This commit is contained in:
parent
e2b0d561bc
commit
1775c73e53
1 changed files with 11 additions and 12 deletions
|
@ -337,9 +337,12 @@ LightColorValues LightCall::validate_() {
|
||||||
void LightCall::transform_parameters_() {
|
void LightCall::transform_parameters_() {
|
||||||
auto traits = this->parent_->get_traits();
|
auto traits = this->parent_->get_traits();
|
||||||
|
|
||||||
// Allow CWWW modes to be set with a white value and/or color temperature. This is used by HA,
|
// Allow CWWW modes to be set with a white value and/or color temperature.
|
||||||
// which doesn't support CWWW modes (yet?), and for compatibility with the pre-colormode model,
|
// This is used in three cases in HA:
|
||||||
// as CWWW and RGBWW lights used to represent their values as white + color temperature.
|
// - CW/WW lights, which set the "brightness" and "color_temperature"
|
||||||
|
// - RGBWW lights with color_interlock=true, which also sets "brightness" and
|
||||||
|
// "color_temperature" (without color_interlock, CW/WW are set directly)
|
||||||
|
// - Legacy Home Assistant (pre-colormode), which sets "white" and "color_temperature"
|
||||||
if (((this->white_.has_value() && *this->white_ > 0.0f) || this->color_temperature_.has_value()) && //
|
if (((this->white_.has_value() && *this->white_ > 0.0f) || this->color_temperature_.has_value()) && //
|
||||||
(*this->color_mode_ & ColorCapability::COLD_WARM_WHITE) && //
|
(*this->color_mode_ & ColorCapability::COLD_WARM_WHITE) && //
|
||||||
!(*this->color_mode_ & ColorCapability::WHITE) && //
|
!(*this->color_mode_ & ColorCapability::WHITE) && //
|
||||||
|
@ -347,21 +350,17 @@ void LightCall::transform_parameters_() {
|
||||||
traits.get_min_mireds() > 0.0f && traits.get_max_mireds() > 0.0f) {
|
traits.get_min_mireds() > 0.0f && traits.get_max_mireds() > 0.0f) {
|
||||||
ESP_LOGD(TAG, "'%s' - Setting cold/warm white channels using white/color temperature values.",
|
ESP_LOGD(TAG, "'%s' - Setting cold/warm white channels using white/color temperature values.",
|
||||||
this->parent_->get_name().c_str());
|
this->parent_->get_name().c_str());
|
||||||
auto current_values = this->parent_->remote_values;
|
|
||||||
if (this->color_temperature_.has_value()) {
|
if (this->color_temperature_.has_value()) {
|
||||||
const float white =
|
|
||||||
this->white_.value_or(fmaxf(current_values.get_cold_white(), current_values.get_warm_white()));
|
|
||||||
const float color_temp = clamp(*this->color_temperature_, traits.get_min_mireds(), traits.get_max_mireds());
|
const float color_temp = clamp(*this->color_temperature_, traits.get_min_mireds(), traits.get_max_mireds());
|
||||||
const float ww_fraction =
|
const float ww_fraction =
|
||||||
(color_temp - traits.get_min_mireds()) / (traits.get_max_mireds() - traits.get_min_mireds());
|
(color_temp - traits.get_min_mireds()) / (traits.get_max_mireds() - traits.get_min_mireds());
|
||||||
const float cw_fraction = 1.0f - ww_fraction;
|
const float cw_fraction = 1.0f - ww_fraction;
|
||||||
const float max_cw_ww = std::max(ww_fraction, cw_fraction);
|
const float max_cw_ww = std::max(ww_fraction, cw_fraction);
|
||||||
this->cold_white_ = white * gamma_uncorrect(cw_fraction / max_cw_ww, this->parent_->get_gamma_correct());
|
this->cold_white_ = gamma_uncorrect(cw_fraction / max_cw_ww, this->parent_->get_gamma_correct());
|
||||||
this->warm_white_ = white * gamma_uncorrect(ww_fraction / max_cw_ww, this->parent_->get_gamma_correct());
|
this->warm_white_ = gamma_uncorrect(ww_fraction / max_cw_ww, this->parent_->get_gamma_correct());
|
||||||
} else {
|
}
|
||||||
const float max_cw_ww = std::max(current_values.get_warm_white(), current_values.get_cold_white());
|
if (this->white_.has_value()) {
|
||||||
this->cold_white_ = *this->white_ * current_values.get_cold_white() / max_cw_ww;
|
this->brightness_ = *this->white_;
|
||||||
this->warm_white_ = *this->white_ * current_values.get_warm_white() / max_cw_ww;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue