ESPHome 2025.7.2
Loading...
Searching...
No Matches
esphome::light::LightCall Class Reference

This class represents a requested change in a light state. More...

#include <light_call.h>

Public Member Functions

 LightCall (LightState *parent)
 
LightCallset_state (optional< bool > state)
 Set the binary ON/OFF state of the light.
 
LightCallset_state (bool state)
 Set the binary ON/OFF state of the light.
 
LightCallset_transition_length (optional< uint32_t > transition_length)
 Set the transition length of this call in milliseconds.
 
LightCallset_transition_length (uint32_t transition_length)
 Set the transition length of this call in milliseconds.
 
LightCallset_transition_length_if_supported (uint32_t transition_length)
 Set the transition length property if the light supports transitions.
 
LightCallset_flash_length (optional< uint32_t > flash_length)
 Start and set the flash length of this call in milliseconds.
 
LightCallset_flash_length (uint32_t flash_length)
 Start and set the flash length of this call in milliseconds.
 
LightCallset_brightness (optional< float > brightness)
 Set the target brightness of the light from 0.0 (fully off) to 1.0 (fully on)
 
LightCallset_brightness (float brightness)
 Set the target brightness of the light from 0.0 (fully off) to 1.0 (fully on)
 
LightCallset_brightness_if_supported (float brightness)
 Set the brightness property if the light supports brightness.
 
LightCallset_color_mode (optional< ColorMode > color_mode)
 Set the color mode of the light.
 
LightCallset_color_mode (ColorMode color_mode)
 Set the color mode of the light.
 
LightCallset_color_mode_if_supported (ColorMode color_mode)
 Set the color mode of the light, if this mode is supported.
 
LightCallset_color_brightness (optional< float > brightness)
 Set the color brightness of the light from 0.0 (no color) to 1.0 (fully on)
 
LightCallset_color_brightness (float brightness)
 Set the color brightness of the light from 0.0 (no color) to 1.0 (fully on)
 
LightCallset_color_brightness_if_supported (float brightness)
 Set the color brightness property if the light supports RGBW.
 
LightCallset_red (optional< float > red)
 Set the red RGB value of the light from 0.0 to 1.0.
 
LightCallset_red (float red)
 Set the red RGB value of the light from 0.0 to 1.0.
 
LightCallset_red_if_supported (float red)
 Set the red property if the light supports RGB.
 
LightCallset_green (optional< float > green)
 Set the green RGB value of the light from 0.0 to 1.0.
 
LightCallset_green (float green)
 Set the green RGB value of the light from 0.0 to 1.0.
 
LightCallset_green_if_supported (float green)
 Set the green property if the light supports RGB.
 
LightCallset_blue (optional< float > blue)
 Set the blue RGB value of the light from 0.0 to 1.0.
 
LightCallset_blue (float blue)
 Set the blue RGB value of the light from 0.0 to 1.0.
 
LightCallset_blue_if_supported (float blue)
 Set the blue property if the light supports RGB.
 
LightCallset_white (optional< float > white)
 Set the white value value of the light from 0.0 to 1.0 for RGBW[W] lights.
 
LightCallset_white (float white)
 Set the white value value of the light from 0.0 to 1.0 for RGBW[W] lights.
 
LightCallset_white_if_supported (float white)
 Set the white property if the light supports RGB.
 
LightCallset_color_temperature (optional< float > color_temperature)
 Set the color temperature of the light in mireds for CWWW or RGBWW lights.
 
LightCallset_color_temperature (float color_temperature)
 Set the color temperature of the light in mireds for CWWW or RGBWW lights.
 
LightCallset_color_temperature_if_supported (float color_temperature)
 Set the color_temperature property if the light supports color temperature.
 
LightCallset_cold_white (optional< float > cold_white)
 Set the cold white value of the light from 0.0 to 1.0.
 
LightCallset_cold_white (float cold_white)
 Set the cold white value of the light from 0.0 to 1.0.
 
LightCallset_cold_white_if_supported (float cold_white)
 Set the cold white property if the light supports cold white output.
 
LightCallset_warm_white (optional< float > warm_white)
 Set the warm white value of the light from 0.0 to 1.0.
 
LightCallset_warm_white (float warm_white)
 Set the warm white value of the light from 0.0 to 1.0.
 
LightCallset_warm_white_if_supported (float warm_white)
 Set the warm white property if the light supports cold white output.
 
LightCallset_effect (optional< std::string > effect)
 Set the effect of the light by its name.
 
LightCallset_effect (const std::string &effect)
 Set the effect of the light by its name.
 
LightCallset_effect (uint32_t effect_number)
 Set the effect of the light by its internal index number (only for internal use).
 
LightCallset_effect (optional< uint32_t > effect_number)
 
LightCallset_publish (bool publish)
 Set whether this light call should trigger a publish state.
 
LightCallset_save (bool save)
 Set whether this light call should trigger a save state to recover them at startup..
 
bool has_state () const
 
bool has_brightness () const
 
bool has_color_brightness () const
 
bool has_red () const
 
bool has_green () const
 
bool has_blue () const
 
bool has_white () const
 
bool has_color_temperature () const
 
bool has_cold_white () const
 
bool has_warm_white () const
 
bool has_color_mode () const
 
LightCallset_rgb (float red, float green, float blue)
 Set the RGB color of the light by RGB values.
 
LightCallset_rgbw (float red, float green, float blue, float white)
 Set the RGBW color of the light by RGB values.
 
LightCallfrom_light_color_values (const LightColorValues &values)
 
void perform ()
 

Protected Types

enum  FieldFlags : uint16_t {
  FLAG_HAS_STATE = 1 << 0 , FLAG_HAS_TRANSITION = 1 << 1 , FLAG_HAS_FLASH = 1 << 2 , FLAG_HAS_EFFECT = 1 << 3 ,
  FLAG_HAS_BRIGHTNESS = 1 << 4 , FLAG_HAS_COLOR_BRIGHTNESS = 1 << 5 , FLAG_HAS_RED = 1 << 6 , FLAG_HAS_GREEN = 1 << 7 ,
  FLAG_HAS_BLUE = 1 << 8 , FLAG_HAS_WHITE = 1 << 9 , FLAG_HAS_COLOR_TEMPERATURE = 1 << 10 , FLAG_HAS_COLD_WHITE = 1 << 11 ,
  FLAG_HAS_WARM_WHITE = 1 << 12 , FLAG_HAS_COLOR_MODE = 1 << 13 , FLAG_PUBLISH = 1 << 14 , FLAG_SAVE = 1 << 15
}
 

Protected Member Functions

ColorMode get_active_color_mode_ ()
 Get the currently targeted, or active if none set, color mode.
 
LightColorValues validate_ ()
 Validate all properties and return the target light color values.
 
ColorMode compute_color_mode_ ()
 
std::set< ColorModeget_suitable_color_modes_ ()
 Get potential color modes for this light call.
 
void transform_parameters_ ()
 Some color modes also can be set using non-native parameters, transform those calls.
 
bool has_transition_ ()
 
bool has_flash_ ()
 
bool has_effect_ ()
 
bool get_publish_ ()
 
bool get_save_ ()
 
void set_flag_ (FieldFlags flag, bool value)
 

Protected Attributes

LightStateparent_
 
uint32_t transition_length_
 
uint32_t flash_length_
 
uint32_t effect_
 
float brightness_
 
float color_brightness_
 
float red_
 
float green_
 
float blue_
 
float white_
 
float color_temperature_
 
float cold_white_
 
float warm_white_
 
uint16_t flags_ {FLAG_PUBLISH | FLAG_SAVE}
 
ColorMode color_mode_
 
bool state_
 

Detailed Description

This class represents a requested change in a light state.

Light state changes are tracked using a bitfield flags_ to minimize memory usage. Each possible light property has a flag indicating whether it has been set. This design keeps LightCall at ~56 bytes to minimize heap fragmentation on ESP8266 and other memory-constrained devices.

Definition at line 18 of file light_call.h.

Member Enumeration Documentation

◆ FieldFlags

enum esphome::light::LightCall::FieldFlags : uint16_t
protected
Enumerator
FLAG_HAS_STATE 
FLAG_HAS_TRANSITION 
FLAG_HAS_FLASH 
FLAG_HAS_EFFECT 
FLAG_HAS_BRIGHTNESS 
FLAG_HAS_COLOR_BRIGHTNESS 
FLAG_HAS_RED 
FLAG_HAS_GREEN 
FLAG_HAS_BLUE 
FLAG_HAS_WHITE 
FLAG_HAS_COLOR_TEMPERATURE 
FLAG_HAS_COLD_WHITE 
FLAG_HAS_WARM_WHITE 
FLAG_HAS_COLOR_MODE 
FLAG_PUBLISH 
FLAG_SAVE 

Definition at line 191 of file light_call.h.

Constructor & Destructor Documentation

◆ LightCall()

esphome::light::LightCall::LightCall ( LightState * parent)
inlineexplicit

Definition at line 20 of file light_call.h.

Member Function Documentation

◆ compute_color_mode_()

ColorMode esphome::light::LightCall::compute_color_mode_ ( )
protected

Definition at line 391 of file light_call.cpp.

◆ from_light_color_values()

LightCall & esphome::light::LightCall::from_light_color_values ( const LightColorValues & values)

Definition at line 503 of file light_call.cpp.

◆ get_active_color_mode_()

ColorMode esphome::light::LightCall::get_active_color_mode_ ( )
protected

Get the currently targeted, or active if none set, color mode.

Definition at line 517 of file light_call.cpp.

◆ get_publish_()

bool esphome::light::LightCall::get_publish_ ( )
inlineprotected

Definition at line 213 of file light_call.h.

◆ get_save_()

bool esphome::light::LightCall::get_save_ ( )
inlineprotected

Definition at line 214 of file light_call.h.

◆ get_suitable_color_modes_()

std::set< ColorMode > esphome::light::LightCall::get_suitable_color_modes_ ( )
protected

Get potential color modes for this light call.

Definition at line 437 of file light_call.cpp.

◆ has_blue()

bool esphome::light::LightCall::has_blue ( ) const
inline

Definition at line 144 of file light_call.h.

◆ has_brightness()

bool esphome::light::LightCall::has_brightness ( ) const
inline

Definition at line 140 of file light_call.h.

◆ has_cold_white()

bool esphome::light::LightCall::has_cold_white ( ) const
inline

Definition at line 147 of file light_call.h.

◆ has_color_brightness()

bool esphome::light::LightCall::has_color_brightness ( ) const
inline

Definition at line 141 of file light_call.h.

◆ has_color_mode()

bool esphome::light::LightCall::has_color_mode ( ) const
inline

Definition at line 149 of file light_call.h.

◆ has_color_temperature()

bool esphome::light::LightCall::has_color_temperature ( ) const
inline

Definition at line 146 of file light_call.h.

◆ has_effect_()

bool esphome::light::LightCall::has_effect_ ( )
inlineprotected

Definition at line 212 of file light_call.h.

◆ has_flash_()

bool esphome::light::LightCall::has_flash_ ( )
inlineprotected

Definition at line 211 of file light_call.h.

◆ has_green()

bool esphome::light::LightCall::has_green ( ) const
inline

Definition at line 143 of file light_call.h.

◆ has_red()

bool esphome::light::LightCall::has_red ( ) const
inline

Definition at line 142 of file light_call.h.

◆ has_state()

bool esphome::light::LightCall::has_state ( ) const
inline

Definition at line 139 of file light_call.h.

◆ has_transition_()

bool esphome::light::LightCall::has_transition_ ( )
inlineprotected

Definition at line 210 of file light_call.h.

◆ has_warm_white()

bool esphome::light::LightCall::has_warm_white ( ) const
inline

Definition at line 148 of file light_call.h.

◆ has_white()

bool esphome::light::LightCall::has_white ( ) const
inline

Definition at line 145 of file light_call.h.

◆ perform()

void esphome::light::LightCall::perform ( )

Definition at line 47 of file light_call.cpp.

◆ set_blue() [1/2]

LightCall & esphome::light::LightCall::set_blue ( float blue)

Set the blue RGB value of the light from 0.0 to 1.0.

Note that this only controls the color of the light, not its brightness.

◆ set_blue() [2/2]

LightCall & esphome::light::LightCall::set_blue ( optional< float > blue)

Set the blue RGB value of the light from 0.0 to 1.0.

Note that this only controls the color of the light, not its brightness.

◆ set_blue_if_supported()

LightCall & esphome::light::LightCall::set_blue_if_supported ( float blue)

Set the blue property if the light supports RGB.

Definition at line 550 of file light_call.cpp.

◆ set_brightness() [1/2]

LightCall & esphome::light::LightCall::set_brightness ( float brightness)

Set the target brightness of the light from 0.0 (fully off) to 1.0 (fully on)

◆ set_brightness() [2/2]

LightCall & esphome::light::LightCall::set_brightness ( optional< float > brightness)

Set the target brightness of the light from 0.0 (fully off) to 1.0 (fully on)

◆ set_brightness_if_supported()

LightCall & esphome::light::LightCall::set_brightness_if_supported ( float brightness)

Set the brightness property if the light supports brightness.

Definition at line 525 of file light_call.cpp.

◆ set_cold_white() [1/2]

LightCall & esphome::light::LightCall::set_cold_white ( float cold_white)

Set the cold white value of the light from 0.0 to 1.0.

◆ set_cold_white() [2/2]

LightCall & esphome::light::LightCall::set_cold_white ( optional< float > cold_white)

Set the cold white value of the light from 0.0 to 1.0.

◆ set_cold_white_if_supported()

LightCall & esphome::light::LightCall::set_cold_white_if_supported ( float cold_white)

Set the cold white property if the light supports cold white output.

Definition at line 566 of file light_call.cpp.

◆ set_color_brightness() [1/2]

LightCall & esphome::light::LightCall::set_color_brightness ( float brightness)

Set the color brightness of the light from 0.0 (no color) to 1.0 (fully on)

◆ set_color_brightness() [2/2]

LightCall & esphome::light::LightCall::set_color_brightness ( optional< float > brightness)

Set the color brightness of the light from 0.0 (no color) to 1.0 (fully on)

◆ set_color_brightness_if_supported()

LightCall & esphome::light::LightCall::set_color_brightness_if_supported ( float brightness)

Set the color brightness property if the light supports RGBW.

Definition at line 535 of file light_call.cpp.

◆ set_color_mode() [1/2]

LightCall & esphome::light::LightCall::set_color_mode ( ColorMode color_mode)

Set the color mode of the light.

◆ set_color_mode() [2/2]

LightCall & esphome::light::LightCall::set_color_mode ( optional< ColorMode > color_mode)

Set the color mode of the light.

◆ set_color_mode_if_supported()

LightCall & esphome::light::LightCall::set_color_mode_if_supported ( ColorMode color_mode)

Set the color mode of the light, if this mode is supported.

Definition at line 530 of file light_call.cpp.

◆ set_color_temperature() [1/2]

LightCall & esphome::light::LightCall::set_color_temperature ( float color_temperature)

Set the color temperature of the light in mireds for CWWW or RGBWW lights.

◆ set_color_temperature() [2/2]

LightCall & esphome::light::LightCall::set_color_temperature ( optional< float > color_temperature)

Set the color temperature of the light in mireds for CWWW or RGBWW lights.

◆ set_color_temperature_if_supported()

LightCall & esphome::light::LightCall::set_color_temperature_if_supported ( float color_temperature)

Set the color_temperature property if the light supports color temperature.

Definition at line 560 of file light_call.cpp.

◆ set_effect() [1/4]

LightCall & esphome::light::LightCall::set_effect ( const std::string & effect)

Set the effect of the light by its name.

Definition at line 482 of file light_call.cpp.

◆ set_effect() [2/4]

LightCall & esphome::light::LightCall::set_effect ( optional< std::string > effect)

Set the effect of the light by its name.

◆ set_effect() [3/4]

LightCall & esphome::light::LightCall::set_effect ( optional< uint32_t > effect_number)

Definition at line 599 of file light_call.cpp.

◆ set_effect() [4/4]

LightCall & esphome::light::LightCall::set_effect ( uint32_t effect_number)

Set the effect of the light by its internal index number (only for internal use).

Definition at line 594 of file light_call.cpp.

◆ set_flag_()

void esphome::light::LightCall::set_flag_ ( FieldFlags flag,
bool value )
inlineprotected

Definition at line 217 of file light_call.h.

◆ set_flash_length() [1/2]

LightCall & esphome::light::LightCall::set_flash_length ( optional< uint32_t > flash_length)

Start and set the flash length of this call in milliseconds.

◆ set_flash_length() [2/2]

LightCall & esphome::light::LightCall::set_flash_length ( uint32_t flash_length)

Start and set the flash length of this call in milliseconds.

◆ set_green() [1/2]

LightCall & esphome::light::LightCall::set_green ( float green)

Set the green RGB value of the light from 0.0 to 1.0.

Note that this only controls the color of the light, not its brightness.

◆ set_green() [2/2]

LightCall & esphome::light::LightCall::set_green ( optional< float > green)

Set the green RGB value of the light from 0.0 to 1.0.

Note that this only controls the color of the light, not its brightness.

◆ set_green_if_supported()

LightCall & esphome::light::LightCall::set_green_if_supported ( float green)

Set the green property if the light supports RGB.

Definition at line 545 of file light_call.cpp.

◆ set_publish()

LightCall & esphome::light::LightCall::set_publish ( bool publish)

Set whether this light call should trigger a publish state.

Definition at line 606 of file light_call.cpp.

◆ set_red() [1/2]

LightCall & esphome::light::LightCall::set_red ( float red)

Set the red RGB value of the light from 0.0 to 1.0.

Note that this only controls the color of the light, not its brightness.

◆ set_red() [2/2]

LightCall & esphome::light::LightCall::set_red ( optional< float > red)

Set the red RGB value of the light from 0.0 to 1.0.

Note that this only controls the color of the light, not its brightness.

◆ set_red_if_supported()

LightCall & esphome::light::LightCall::set_red_if_supported ( float red)

Set the red property if the light supports RGB.

Definition at line 540 of file light_call.cpp.

◆ set_rgb()

LightCall & esphome::light::LightCall::set_rgb ( float red,
float green,
float blue )

Set the RGB color of the light by RGB values.

Please note that this only changes the color of the light, not the brightness.

Parameters
redThe red color value from 0.0 to 1.0.
greenThe green color value from 0.0 to 1.0.
blueThe blue color value from 0.0 to 1.0.
Returns
The light call for chaining setters.

Definition at line 614 of file light_call.cpp.

◆ set_rgbw()

LightCall & esphome::light::LightCall::set_rgbw ( float red,
float green,
float blue,
float white )

Set the RGBW color of the light by RGB values.

Please note that this only changes the color of the light, not the brightness.

Parameters
redThe red color value from 0.0 to 1.0.
greenThe green color value from 0.0 to 1.0.
blueThe blue color value from 0.0 to 1.0.
whiteThe white color value from 0.0 to 1.0.
Returns
The light call for chaining setters.

Definition at line 620 of file light_call.cpp.

◆ set_save()

LightCall & esphome::light::LightCall::set_save ( bool save)

Set whether this light call should trigger a save state to recover them at startup..

Definition at line 610 of file light_call.cpp.

◆ set_state() [1/2]

LightCall & esphome::light::LightCall::set_state ( bool state)

Set the binary ON/OFF state of the light.

◆ set_state() [2/2]

LightCall & esphome::light::LightCall::set_state ( optional< bool > state)

Set the binary ON/OFF state of the light.

◆ set_transition_length() [1/2]

LightCall & esphome::light::LightCall::set_transition_length ( optional< uint32_t > transition_length)

Set the transition length of this call in milliseconds.

This argument is ignored for starting flashes and effects.

Defaults to the default transition length defined in the light configuration.

◆ set_transition_length() [2/2]

LightCall & esphome::light::LightCall::set_transition_length ( uint32_t transition_length)

Set the transition length of this call in milliseconds.

This argument is ignored for starting flashes and effects.

Defaults to the default transition length defined in the light configuration.

◆ set_transition_length_if_supported()

LightCall & esphome::light::LightCall::set_transition_length_if_supported ( uint32_t transition_length)

Set the transition length property if the light supports transitions.

Definition at line 520 of file light_call.cpp.

◆ set_warm_white() [1/2]

LightCall & esphome::light::LightCall::set_warm_white ( float warm_white)

Set the warm white value of the light from 0.0 to 1.0.

◆ set_warm_white() [2/2]

LightCall & esphome::light::LightCall::set_warm_white ( optional< float > warm_white)

Set the warm white value of the light from 0.0 to 1.0.

◆ set_warm_white_if_supported()

LightCall & esphome::light::LightCall::set_warm_white_if_supported ( float warm_white)

Set the warm white property if the light supports cold white output.

Definition at line 571 of file light_call.cpp.

◆ set_white() [1/2]

LightCall & esphome::light::LightCall::set_white ( float white)

Set the white value value of the light from 0.0 to 1.0 for RGBW[W] lights.

◆ set_white() [2/2]

LightCall & esphome::light::LightCall::set_white ( optional< float > white)

Set the white value value of the light from 0.0 to 1.0 for RGBW[W] lights.

◆ set_white_if_supported()

LightCall & esphome::light::LightCall::set_white_if_supported ( float white)

Set the white property if the light supports RGB.

Definition at line 555 of file light_call.cpp.

◆ transform_parameters_()

void esphome::light::LightCall::transform_parameters_ ( )
protected

Some color modes also can be set using non-native parameters, transform those calls.

Definition at line 358 of file light_call.cpp.

◆ validate_()

LightColorValues esphome::light::LightCall::validate_ ( )
protected

Validate all properties and return the target light color values.

Definition at line 150 of file light_call.cpp.

Field Documentation

◆ blue_

float esphome::light::LightCall::blue_
protected

Definition at line 236 of file light_call.h.

◆ brightness_

float esphome::light::LightCall::brightness_
protected

Definition at line 232 of file light_call.h.

◆ cold_white_

float esphome::light::LightCall::cold_white_
protected

Definition at line 239 of file light_call.h.

◆ color_brightness_

float esphome::light::LightCall::color_brightness_
protected

Definition at line 233 of file light_call.h.

◆ color_mode_

ColorMode esphome::light::LightCall::color_mode_
protected

Definition at line 244 of file light_call.h.

◆ color_temperature_

float esphome::light::LightCall::color_temperature_
protected

Definition at line 238 of file light_call.h.

◆ effect_

uint32_t esphome::light::LightCall::effect_
protected

Definition at line 231 of file light_call.h.

◆ flags_

uint16_t esphome::light::LightCall::flags_ {FLAG_PUBLISH | FLAG_SAVE}
protected

Definition at line 243 of file light_call.h.

◆ flash_length_

uint32_t esphome::light::LightCall::flash_length_
protected

Definition at line 230 of file light_call.h.

◆ green_

float esphome::light::LightCall::green_
protected

Definition at line 235 of file light_call.h.

◆ parent_

LightState* esphome::light::LightCall::parent_
protected

Definition at line 225 of file light_call.h.

◆ red_

float esphome::light::LightCall::red_
protected

Definition at line 234 of file light_call.h.

◆ state_

bool esphome::light::LightCall::state_
protected

Definition at line 245 of file light_call.h.

◆ transition_length_

uint32_t esphome::light::LightCall::transition_length_
protected

Definition at line 229 of file light_call.h.

◆ warm_white_

float esphome::light::LightCall::warm_white_
protected

Definition at line 240 of file light_call.h.

◆ white_

float esphome::light::LightCall::white_
protected

Definition at line 237 of file light_call.h.


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