mirror of
https://github.com/esphome/esphome.git
synced 2025-10-09 21:33:48 +01:00
Add rgbct and color_temperature light platforms (#2138)
Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl>
This commit is contained in:
@@ -163,6 +163,13 @@ class LightColorValues {
|
||||
this->as_cwww(cold_white, warm_white, gamma, constant_brightness);
|
||||
}
|
||||
|
||||
/// Convert these light color values to an RGB+CT+BR representation with the given parameters.
|
||||
void as_rgbct(float color_temperature_cw, float color_temperature_ww, float *red, float *green, float *blue,
|
||||
float *color_temperature, float *white_brightness, float gamma = 0) const {
|
||||
this->as_rgb(red, green, blue, gamma);
|
||||
this->as_ct(color_temperature_cw, color_temperature_ww, color_temperature, white_brightness, gamma);
|
||||
}
|
||||
|
||||
/// Convert these light color values to an CWWW representation with the given parameters.
|
||||
void as_cwww(float *cold_white, float *warm_white, float gamma = 0, bool constant_brightness = false) const {
|
||||
if (this->color_mode_ & ColorCapability::COLD_WARM_WHITE) {
|
||||
@@ -187,6 +194,19 @@ class LightColorValues {
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert these light color values to a CT+BR representation with the given parameters.
|
||||
void as_ct(float color_temperature_cw, float color_temperature_ww, float *color_temperature, float *white_brightness,
|
||||
float gamma = 0) const {
|
||||
const float white_level = this->color_mode_ & ColorCapability::RGB ? this->white_ : 1;
|
||||
if (this->color_mode_ & ColorCapability::COLOR_TEMPERATURE) {
|
||||
*color_temperature =
|
||||
(this->color_temperature_ - color_temperature_cw) / (color_temperature_ww - color_temperature_cw);
|
||||
*white_brightness = gamma_correct(this->state_ * this->brightness_ * white_level, gamma);
|
||||
} else { // Probably wont get here but put this here anyway.
|
||||
*white_brightness = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// Compare this LightColorValues to rhs, return true if and only if all attributes match.
|
||||
bool operator==(const LightColorValues &rhs) const {
|
||||
return color_mode_ == rhs.color_mode_ && state_ == rhs.state_ && brightness_ == rhs.brightness_ &&
|
||||
|
@@ -175,13 +175,23 @@ void LightState::current_values_as_rgbw(float *red, float *green, float *blue, f
|
||||
}
|
||||
void LightState::current_values_as_rgbww(float *red, float *green, float *blue, float *cold_white, float *warm_white,
|
||||
bool constant_brightness) {
|
||||
auto traits = this->get_traits();
|
||||
this->current_values.as_rgbww(red, green, blue, cold_white, warm_white, this->gamma_correct_, constant_brightness);
|
||||
}
|
||||
void LightState::current_values_as_rgbct(float *red, float *green, float *blue, float *color_temperature,
|
||||
float *white_brightness) {
|
||||
auto traits = this->get_traits();
|
||||
this->current_values.as_rgbct(traits.get_min_mireds(), traits.get_max_mireds(), red, green, blue, color_temperature,
|
||||
white_brightness, this->gamma_correct_);
|
||||
}
|
||||
void LightState::current_values_as_cwww(float *cold_white, float *warm_white, bool constant_brightness) {
|
||||
auto traits = this->get_traits();
|
||||
this->current_values.as_cwww(cold_white, warm_white, this->gamma_correct_, constant_brightness);
|
||||
}
|
||||
void LightState::current_values_as_ct(float *color_temperature, float *white_brightness) {
|
||||
auto traits = this->get_traits();
|
||||
this->current_values.as_ct(traits.get_min_mireds(), traits.get_max_mireds(), color_temperature, white_brightness,
|
||||
this->gamma_correct_);
|
||||
}
|
||||
|
||||
void LightState::start_effect_(uint32_t effect_index) {
|
||||
this->stop_effect_();
|
||||
|
@@ -128,8 +128,13 @@ class LightState : public Nameable, public Component {
|
||||
void current_values_as_rgbww(float *red, float *green, float *blue, float *cold_white, float *warm_white,
|
||||
bool constant_brightness = false);
|
||||
|
||||
void current_values_as_rgbct(float *red, float *green, float *blue, float *color_temperature,
|
||||
float *white_brightness);
|
||||
|
||||
void current_values_as_cwww(float *cold_white, float *warm_white, bool constant_brightness = false);
|
||||
|
||||
void current_values_as_ct(float *color_temperature, float *white_brightness);
|
||||
|
||||
protected:
|
||||
friend LightOutput;
|
||||
friend LightCall;
|
||||
|
Reference in New Issue
Block a user