ESPHome  2024.10.2
light_call.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "light_color_values.h"
5 #include <set>
6 
7 namespace esphome {
8 namespace light {
9 
10 class LightState;
11 
14 class LightCall {
15  public:
16  explicit LightCall(LightState *parent) : parent_(parent) {}
17 
21  LightCall &set_state(bool state);
35  LightCall &set_transition_length(uint32_t transition_length);
37  LightCall &set_transition_length_if_supported(uint32_t transition_length);
41  LightCall &set_flash_length(uint32_t flash_length);
45  LightCall &set_brightness(float brightness);
47  LightCall &set_brightness_if_supported(float brightness);
48 
52  LightCall &set_color_mode(ColorMode color_mode);
55 
59  LightCall &set_color_brightness(float brightness);
71  LightCall &set_red(float red);
73  LightCall &set_red_if_supported(float red);
83  LightCall &set_green(float green);
85  LightCall &set_green_if_supported(float green);
95  LightCall &set_blue(float blue);
97  LightCall &set_blue_if_supported(float blue);
101  LightCall &set_white(float white);
103  LightCall &set_white_if_supported(float white);
105  LightCall &set_color_temperature(optional<float> color_temperature);
107  LightCall &set_color_temperature(float color_temperature);
109  LightCall &set_color_temperature_if_supported(float color_temperature);
113  LightCall &set_cold_white(float cold_white);
115  LightCall &set_cold_white_if_supported(float cold_white);
119  LightCall &set_warm_white(float warm_white);
121  LightCall &set_warm_white_if_supported(float warm_white);
125  LightCall &set_effect(const std::string &effect);
127  LightCall &set_effect(uint32_t effect_number);
128  LightCall &set_effect(optional<uint32_t> effect_number);
130  LightCall &set_publish(bool publish);
132  LightCall &set_save(bool save);
133 
143  LightCall &set_rgb(float red, float green, float blue);
154  LightCall &set_rgbw(float red, float green, float blue, float white);
156 
157  void perform();
158 
159  protected:
162 
165 
169  std::set<ColorMode> get_suitable_color_modes_();
171  void transform_parameters_();
172 
173  bool has_transition_() { return this->transition_length_.has_value(); }
174  bool has_flash_() { return this->flash_length_.has_value(); }
175  bool has_effect_() { return this->effect_.has_value(); }
176 
192  bool publish_{true};
193  bool save_{true};
194 };
195 
196 } // namespace light
197 } // namespace esphome
LightCall & set_save(bool save)
Set whether this light call should trigger a save state to recover them at startup..
Definition: light_call.cpp:673
ColorMode
Color modes are a combination of color capabilities that can be used at the same time.
Definition: color_mode.h:49
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition: light_state.h:34
LightCall & set_color_brightness(optional< float > brightness)
Set the color brightness of the light from 0.0 (no color) to 1.0 (fully on)
Definition: light_call.cpp:592
LightCall & set_publish(bool publish)
Set whether this light call should trigger a publish state.
Definition: light_call.cpp:669
LightCall & set_red(optional< float > red)
Set the red RGB value of the light from 0.0 to 1.0.
Definition: light_call.cpp:600
LightCall & set_color_temperature(optional< float > color_temperature)
Set the color temperature of the light in mireds for CWWW or RGBWW lights.
Definition: light_call.cpp:632
LightCall & set_green_if_supported(float green)
Set the green property if the light supports RGB.
Definition: light_call.cpp:521
optional< float > warm_white_
Definition: light_call.h:190
LightCall & set_cold_white(optional< float > cold_white)
Set the cold white value of the light from 0.0 to 1.0.
Definition: light_call.cpp:640
optional< uint32_t > effect_
Definition: light_call.h:191
optional< float > blue_
Definition: light_call.h:186
LightCall & set_rgb(float red, float green, float blue)
Set the RGB color of the light by RGB values.
Definition: light_call.cpp:677
LightCall & set_color_brightness_if_supported(float brightness)
Set the color brightness property if the light supports RGBW.
Definition: light_call.cpp:511
optional< float > red_
Definition: light_call.h:184
optional< float > color_brightness_
Definition: light_call.h:183
optional< float > cold_white_
Definition: light_call.h:189
LightCall & set_color_mode(optional< ColorMode > color_mode)
Set the color mode of the light.
Definition: light_call.cpp:584
LightColorValues validate_()
Validate all properties and return the target light color values.
Definition: light_call.cpp:133
bool has_value() const
Definition: optional.h:87
LightCall & set_transition_length(optional< uint32_t > transition_length)
Set the transition length of this call in milliseconds.
Definition: light_call.cpp:560
LightCall(LightState *parent)
Definition: light_call.h:16
optional< bool > state_
Definition: light_call.h:178
LightCall & set_warm_white_if_supported(float warm_white)
Set the warm white property if the light supports cold white output.
Definition: light_call.cpp:547
LightCall & from_light_color_values(const LightColorValues &values)
Definition: light_call.cpp:479
optional< float > brightness_
Definition: light_call.h:182
optional< float > color_temperature_
Definition: light_call.h:188
This class represents the color state for a light object.
ColorMode get_active_color_mode_()
Get the currently targeted, or active if none set, color mode.
Definition: light_call.cpp:493
ColorMode compute_color_mode_()
Definition: light_call.cpp:367
LightCall & set_transition_length_if_supported(uint32_t transition_length)
Set the transition length property if the light supports transitions.
Definition: light_call.cpp:496
LightCall & set_color_temperature_if_supported(float color_temperature)
Set the color_temperature property if the light supports color temperature.
Definition: light_call.cpp:536
LightCall & set_color_mode_if_supported(ColorMode color_mode)
Set the color mode of the light, if this mode is supported.
Definition: light_call.cpp:506
This class represents a requested change in a light state.
Definition: light_call.h:14
LightCall & set_state(optional< bool > state)
Set the binary ON/OFF state of the light.
Definition: light_call.cpp:552
void transform_parameters_()
Some color modes also can be set using non-native parameters, transform those calls.
Definition: light_call.cpp:337
LightCall & set_warm_white(optional< float > warm_white)
Set the warm white value of the light from 0.0 to 1.0.
Definition: light_call.cpp:648
LightCall & set_effect(optional< std::string > effect)
Set the effect of the light by its name.
Definition: light_call.cpp:656
LightCall & set_cold_white_if_supported(float cold_white)
Set the cold white property if the light supports cold white output.
Definition: light_call.cpp:542
optional< ColorMode > color_mode_
Definition: light_call.h:181
std::set< ColorMode > get_suitable_color_modes_()
Get potential color modes for this light call.
Definition: light_call.cpp:413
optional< float > white_
Definition: light_call.h:187
LightCall & set_rgbw(float red, float green, float blue, float white)
Set the RGBW color of the light by RGB values.
Definition: light_call.cpp:683
optional< uint32_t > flash_length_
Definition: light_call.h:180
LightCall & set_flash_length(optional< uint32_t > flash_length)
Start and set the flash length of this call in milliseconds.
Definition: light_call.cpp:568
LightCall & set_green(optional< float > green)
Set the green RGB value of the light from 0.0 to 1.0.
Definition: light_call.cpp:608
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
optional< float > green_
Definition: light_call.h:185
optional< uint32_t > transition_length_
Definition: light_call.h:179
LightCall & set_brightness_if_supported(float brightness)
Set the brightness property if the light supports brightness.
Definition: light_call.cpp:501
LightCall & set_white(optional< float > white)
Set the white value value of the light from 0.0 to 1.0 for RGBW[W] lights.
Definition: light_call.cpp:624
LightCall & set_brightness(optional< float > brightness)
Set the target brightness of the light from 0.0 (fully off) to 1.0 (fully on)
Definition: light_call.cpp:576
LightCall & set_blue_if_supported(float blue)
Set the blue property if the light supports RGB.
Definition: light_call.cpp:526
LightCall & set_white_if_supported(float white)
Set the white property if the light supports RGB.
Definition: light_call.cpp:531
LightCall & set_blue(optional< float > blue)
Set the blue RGB value of the light from 0.0 to 1.0.
Definition: light_call.cpp:616
bool state
Definition: fan.h:34
LightCall & set_red_if_supported(float red)
Set the red property if the light supports RGB.
Definition: light_call.cpp:516