ESPHome  2022.8.0
Public Member Functions | Static Public Member Functions | Protected Attributes
esphome::light::LightColorValues Class Reference

This class represents the color state for a light object. More...

#include <light_color_values.h>

Public Member Functions

 LightColorValues ()
 Construct the LightColorValues with all attributes enabled, but state set to off. More...
 
 LightColorValues (ColorMode color_mode, float state, float brightness, float color_brightness, float red, float green, float blue, float white, float color_temperature, float cold_white, float warm_white)
 
void normalize_color ()
 Normalize the color (RGB/W) component. More...
 
void as_binary (bool *binary) const
 Convert these light color values to a binary representation and write them to binary. More...
 
void as_brightness (float *brightness, float gamma=0) const
 Convert these light color values to a brightness-only representation and write them to brightness. More...
 
void as_rgb (float *red, float *green, float *blue, float gamma=0, bool color_interlock=false) const
 Convert these light color values to an RGB representation and write them to red, green, blue. More...
 
void as_rgbw (float *red, float *green, float *blue, float *white, float gamma=0, bool color_interlock=false) const
 Convert these light color values to an RGBW representation and write them to red, green, blue, white. More...
 
void as_rgbww (float *red, float *green, float *blue, float *cold_white, float *warm_white, float gamma=0, bool constant_brightness=false) const
 Convert these light color values to an RGBWW representation with the given parameters. More...
 
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
 Convert these light color values to an RGB+CT+BR representation with the given parameters. More...
 
void as_cwww (float *cold_white, float *warm_white, float gamma=0, bool constant_brightness=false) const
 Convert these light color values to an CWWW representation with the given parameters. More...
 
void as_ct (float color_temperature_cw, float color_temperature_ww, float *color_temperature, float *white_brightness, float gamma=0) const
 Convert these light color values to a CT+BR representation with the given parameters. More...
 
bool operator== (const LightColorValues &rhs) const
 Compare this LightColorValues to rhs, return true if and only if all attributes match. More...
 
bool operator!= (const LightColorValues &rhs) const
 
ColorMode get_color_mode () const
 Get the color mode of these light color values. More...
 
void set_color_mode (ColorMode color_mode)
 Set the color mode of these light color values. More...
 
float get_state () const
 Get the state of these light color values. In range from 0.0 (off) to 1.0 (on) More...
 
bool is_on () const
 Get the binary true/false state of these light color values. More...
 
void set_state (float state)
 Set the state of these light color values. In range from 0.0 (off) to 1.0 (on) More...
 
void set_state (bool state)
 Set the state of these light color values as a binary true/false. More...
 
float get_brightness () const
 Get the brightness property of these light color values. In range 0.0 to 1.0. More...
 
void set_brightness (float brightness)
 Set the brightness property of these light color values. In range 0.0 to 1.0. More...
 
float get_color_brightness () const
 Get the color brightness property of these light color values. In range 0.0 to 1.0. More...
 
void set_color_brightness (float brightness)
 Set the color brightness property of these light color values. In range 0.0 to 1.0. More...
 
float get_red () const
 Get the red property of these light color values. In range 0.0 to 1.0. More...
 
void set_red (float red)
 Set the red property of these light color values. In range 0.0 to 1.0. More...
 
float get_green () const
 Get the green property of these light color values. In range 0.0 to 1.0. More...
 
void set_green (float green)
 Set the green property of these light color values. In range 0.0 to 1.0. More...
 
float get_blue () const
 Get the blue property of these light color values. In range 0.0 to 1.0. More...
 
void set_blue (float blue)
 Set the blue property of these light color values. In range 0.0 to 1.0. More...
 
float get_white () const
 Get the white property of these light color values. In range 0.0 to 1.0. More...
 
void set_white (float white)
 Set the white property of these light color values. In range 0.0 to 1.0. More...
 
float get_color_temperature () const
 Get the color temperature property of these light color values in mired. More...
 
void set_color_temperature (float color_temperature)
 Set the color temperature property of these light color values in mired. More...
 
float get_cold_white () const
 Get the cold white property of these light color values. In range 0.0 to 1.0. More...
 
void set_cold_white (float cold_white)
 Set the cold white property of these light color values. In range 0.0 to 1.0. More...
 
float get_warm_white () const
 Get the warm white property of these light color values. In range 0.0 to 1.0. More...
 
void set_warm_white (float warm_white)
 Set the warm white property of these light color values. In range 0.0 to 1.0. More...
 

Static Public Member Functions

static LightColorValues lerp (const LightColorValues &start, const LightColorValues &end, float completion)
 Linearly interpolate between the values in start to the values in end. More...
 

Protected Attributes

ColorMode color_mode_
 
float state_
 ON / OFF, float for transition. More...
 
float brightness_
 
float color_brightness_
 
float red_
 
float green_
 
float blue_
 
float white_
 
float color_temperature_
 Color Temperature in Mired. More...
 
float cold_white_
 
float warm_white_
 

Detailed Description

This class represents the color state for a light object.

The representation of the color state is dependent on the active color mode. A color mode consists of multiple color capabilities, and each color capability has its own representation in this class. The fields available are as follows:

Always:

For ON_OFF capability:

For BRIGHTNESS capability:

For RGB capability:

For WHITE capability:

For COLOR_TEMPERATURE capability:

For COLD_WARM_WHITE capability:

All values (except color temperature) are represented using floats in the range 0.0 (off) to 1.0 (on), and are automatically clamped to this range. Properties not used in the current color mode can still have (invalid) values and must not be accessed by the light output.

Definition at line 45 of file light_color_values.h.

Constructor & Destructor Documentation

◆ LightColorValues() [1/2]

esphome::light::LightColorValues::LightColorValues ( )
inline

Construct the LightColorValues with all attributes enabled, but state set to off.

Definition at line 48 of file light_color_values.h.

◆ LightColorValues() [2/2]

esphome::light::LightColorValues::LightColorValues ( ColorMode  color_mode,
float  state,
float  brightness,
float  color_brightness,
float  red,
float  green,
float  blue,
float  white,
float  color_temperature,
float  cold_white,
float  warm_white 
)
inline

Definition at line 61 of file light_color_values.h.

Member Function Documentation

◆ as_binary()

void esphome::light::LightColorValues::as_binary ( bool *  binary) const
inline

Convert these light color values to a binary representation and write them to binary.

Definition at line 130 of file light_color_values.h.

◆ as_brightness()

void esphome::light::LightColorValues::as_brightness ( float *  brightness,
float  gamma = 0 
) const
inline

Convert these light color values to a brightness-only representation and write them to brightness.

Definition at line 133 of file light_color_values.h.

◆ as_ct()

void esphome::light::LightColorValues::as_ct ( float  color_temperature_cw,
float  color_temperature_ww,
float *  color_temperature,
float *  white_brightness,
float  gamma = 0 
) const
inline

Convert these light color values to a CT+BR representation with the given parameters.

Definition at line 199 of file light_color_values.h.

◆ as_cwww()

void esphome::light::LightColorValues::as_cwww ( float *  cold_white,
float *  warm_white,
float  gamma = 0,
bool  constant_brightness = false 
) const
inline

Convert these light color values to an CWWW representation with the given parameters.

Definition at line 175 of file light_color_values.h.

◆ as_rgb()

void esphome::light::LightColorValues::as_rgb ( float *  red,
float *  green,
float *  blue,
float  gamma = 0,
bool  color_interlock = false 
) const
inline

Convert these light color values to an RGB representation and write them to red, green, blue.

Definition at line 138 of file light_color_values.h.

◆ as_rgbct()

void esphome::light::LightColorValues::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
inline

Convert these light color values to an RGB+CT+BR representation with the given parameters.

Definition at line 168 of file light_color_values.h.

◆ as_rgbw()

void esphome::light::LightColorValues::as_rgbw ( float *  red,
float *  green,
float *  blue,
float *  white,
float  gamma = 0,
bool  color_interlock = false 
) const
inline

Convert these light color values to an RGBW representation and write them to red, green, blue, white.

Definition at line 150 of file light_color_values.h.

◆ as_rgbww()

void esphome::light::LightColorValues::as_rgbww ( float *  red,
float *  green,
float *  blue,
float *  cold_white,
float *  warm_white,
float  gamma = 0,
bool  constant_brightness = false 
) const
inline

Convert these light color values to an RGBWW representation with the given parameters.

Definition at line 161 of file light_color_values.h.

◆ get_blue()

float esphome::light::LightColorValues::get_blue ( ) const
inline

Get the blue property of these light color values. In range 0.0 to 1.0.

Definition at line 255 of file light_color_values.h.

◆ get_brightness()

float esphome::light::LightColorValues::get_brightness ( ) const
inline

Get the brightness property of these light color values. In range 0.0 to 1.0.

Definition at line 235 of file light_color_values.h.

◆ get_cold_white()

float esphome::light::LightColorValues::get_cold_white ( ) const
inline

Get the cold white property of these light color values. In range 0.0 to 1.0.

Definition at line 270 of file light_color_values.h.

◆ get_color_brightness()

float esphome::light::LightColorValues::get_color_brightness ( ) const
inline

Get the color brightness property of these light color values. In range 0.0 to 1.0.

Definition at line 240 of file light_color_values.h.

◆ get_color_mode()

ColorMode esphome::light::LightColorValues::get_color_mode ( ) const
inline

Get the color mode of these light color values.

Definition at line 221 of file light_color_values.h.

◆ get_color_temperature()

float esphome::light::LightColorValues::get_color_temperature ( ) const
inline

Get the color temperature property of these light color values in mired.

Definition at line 265 of file light_color_values.h.

◆ get_green()

float esphome::light::LightColorValues::get_green ( ) const
inline

Get the green property of these light color values. In range 0.0 to 1.0.

Definition at line 250 of file light_color_values.h.

◆ get_red()

float esphome::light::LightColorValues::get_red ( ) const
inline

Get the red property of these light color values. In range 0.0 to 1.0.

Definition at line 245 of file light_color_values.h.

◆ get_state()

float esphome::light::LightColorValues::get_state ( ) const
inline

Get the state of these light color values. In range from 0.0 (off) to 1.0 (on)

Definition at line 226 of file light_color_values.h.

◆ get_warm_white()

float esphome::light::LightColorValues::get_warm_white ( ) const
inline

Get the warm white property of these light color values. In range 0.0 to 1.0.

Definition at line 275 of file light_color_values.h.

◆ get_white()

float esphome::light::LightColorValues::get_white ( ) const
inline

Get the white property of these light color values. In range 0.0 to 1.0.

Definition at line 260 of file light_color_values.h.

◆ is_on()

bool esphome::light::LightColorValues::is_on ( ) const
inline

Get the binary true/false state of these light color values.

Definition at line 228 of file light_color_values.h.

◆ lerp()

static LightColorValues esphome::light::LightColorValues::lerp ( const LightColorValues start,
const LightColorValues end,
float  completion 
)
inlinestatic

Linearly interpolate between the values in start to the values in end.

This function linearly interpolates the color value by just interpolating every attribute independently.

Parameters
startThe interpolation start values.
endThe interpolation end values.
completionThe completion value. 0 -> start, 1 -> end.
Returns
The linearly interpolated LightColorValues.

Definition at line 86 of file light_color_values.h.

◆ normalize_color()

void esphome::light::LightColorValues::normalize_color ( )
inline

Normalize the color (RGB/W) component.

Divides all color attributes by the maximum attribute, so effectively set at least one attribute to 1. For example: r=0.3, g=0.5, b=0.4 => r=0.6, g=1.0, b=0.8.

Note that this does NOT retain the brightness information from the color attributes.

Parameters
traitsUsed for determining which attributes to consider.

Definition at line 111 of file light_color_values.h.

◆ operator!=()

bool esphome::light::LightColorValues::operator!= ( const LightColorValues rhs) const
inline

Definition at line 218 of file light_color_values.h.

◆ operator==()

bool esphome::light::LightColorValues::operator== ( const LightColorValues rhs) const
inline

Compare this LightColorValues to rhs, return true if and only if all attributes match.

Definition at line 212 of file light_color_values.h.

◆ set_blue()

void esphome::light::LightColorValues::set_blue ( float  blue)
inline

Set the blue property of these light color values. In range 0.0 to 1.0.

Definition at line 257 of file light_color_values.h.

◆ set_brightness()

void esphome::light::LightColorValues::set_brightness ( float  brightness)
inline

Set the brightness property of these light color values. In range 0.0 to 1.0.

Definition at line 237 of file light_color_values.h.

◆ set_cold_white()

void esphome::light::LightColorValues::set_cold_white ( float  cold_white)
inline

Set the cold white property of these light color values. In range 0.0 to 1.0.

Definition at line 272 of file light_color_values.h.

◆ set_color_brightness()

void esphome::light::LightColorValues::set_color_brightness ( float  brightness)
inline

Set the color brightness property of these light color values. In range 0.0 to 1.0.

Definition at line 242 of file light_color_values.h.

◆ set_color_mode()

void esphome::light::LightColorValues::set_color_mode ( ColorMode  color_mode)
inline

Set the color mode of these light color values.

Definition at line 223 of file light_color_values.h.

◆ set_color_temperature()

void esphome::light::LightColorValues::set_color_temperature ( float  color_temperature)
inline

Set the color temperature property of these light color values in mired.

Definition at line 267 of file light_color_values.h.

◆ set_green()

void esphome::light::LightColorValues::set_green ( float  green)
inline

Set the green property of these light color values. In range 0.0 to 1.0.

Definition at line 252 of file light_color_values.h.

◆ set_red()

void esphome::light::LightColorValues::set_red ( float  red)
inline

Set the red property of these light color values. In range 0.0 to 1.0.

Definition at line 247 of file light_color_values.h.

◆ set_state() [1/2]

void esphome::light::LightColorValues::set_state ( float  state)
inline

Set the state of these light color values. In range from 0.0 (off) to 1.0 (on)

Definition at line 230 of file light_color_values.h.

◆ set_state() [2/2]

void esphome::light::LightColorValues::set_state ( bool  state)
inline

Set the state of these light color values as a binary true/false.

Definition at line 232 of file light_color_values.h.

◆ set_warm_white()

void esphome::light::LightColorValues::set_warm_white ( float  warm_white)
inline

Set the warm white property of these light color values. In range 0.0 to 1.0.

Definition at line 277 of file light_color_values.h.

◆ set_white()

void esphome::light::LightColorValues::set_white ( float  white)
inline

Set the white property of these light color values. In range 0.0 to 1.0.

Definition at line 262 of file light_color_values.h.

Field Documentation

◆ blue_

float esphome::light::LightColorValues::blue_
protected

Definition at line 286 of file light_color_values.h.

◆ brightness_

float esphome::light::LightColorValues::brightness_
protected

Definition at line 282 of file light_color_values.h.

◆ cold_white_

float esphome::light::LightColorValues::cold_white_
protected

Definition at line 289 of file light_color_values.h.

◆ color_brightness_

float esphome::light::LightColorValues::color_brightness_
protected

Definition at line 283 of file light_color_values.h.

◆ color_mode_

ColorMode esphome::light::LightColorValues::color_mode_
protected

Definition at line 280 of file light_color_values.h.

◆ color_temperature_

float esphome::light::LightColorValues::color_temperature_
protected

Color Temperature in Mired.

Definition at line 288 of file light_color_values.h.

◆ green_

float esphome::light::LightColorValues::green_
protected

Definition at line 285 of file light_color_values.h.

◆ red_

float esphome::light::LightColorValues::red_
protected

Definition at line 284 of file light_color_values.h.

◆ state_

float esphome::light::LightColorValues::state_
protected

ON / OFF, float for transition.

Definition at line 281 of file light_color_values.h.

◆ warm_white_

float esphome::light::LightColorValues::warm_white_
protected

Definition at line 290 of file light_color_values.h.

◆ white_

float esphome::light::LightColorValues::white_
protected

Definition at line 287 of file light_color_values.h.


The documentation for this class was generated from the following file: