10 static const char *
const TAG =
"light";
21 ESP_LOGCONFIG(TAG,
"Setting up light '%s'...", this->
get_name().c_str());
24 for (
auto *effect : this->
effects_) {
25 effect->init_internal(
this);
48 recovered.
state =
false;
51 recovered.state =
true;
56 recovered.state = !recovered.state;
66 recovered.state =
false;
69 recovered.state =
true;
73 call.set_color_mode_if_supported(recovered.color_mode);
74 call.set_state(recovered.state);
75 call.set_brightness_if_supported(recovered.brightness);
76 call.set_color_brightness_if_supported(recovered.color_brightness);
77 call.set_red_if_supported(recovered.red);
78 call.set_green_if_supported(recovered.green);
79 call.set_blue_if_supported(recovered.blue);
80 call.set_white_if_supported(recovered.white);
81 call.set_color_temperature_if_supported(recovered.color_temp);
82 call.set_cold_white_if_supported(recovered.cold_white);
83 call.set_warm_white_if_supported(recovered.warm_white);
84 if (recovered.effect != 0) {
85 call.set_effect(recovered.effect);
87 call.set_transition_length_if_supported(0);
92 ESP_LOGCONFIG(TAG,
"Light '%s'", this->
get_name().c_str());
98 ESP_LOGCONFIG(TAG,
" Min Mireds: %.1f", this->
get_traits().get_min_mireds());
99 ESP_LOGCONFIG(TAG,
" Max Mireds: %.1f", this->
get_traits().get_max_mireds());
105 if (effect !=
nullptr) {
113 if (values.has_value()) {
172 for (
auto *effect : effects) {
190 bool constant_brightness) {
194 float *white_brightness) {
196 this->
current_values.
as_rgbct(traits.get_min_mireds(), traits.get_max_mireds(), red, green, blue, color_temperature,
205 this->
current_values.
as_ct(traits.get_min_mireds(), traits.get_max_mireds(), color_temperature, white_brightness,
213 if (effect_index == 0)
218 effect->start_internal();
229 if (effect !=
nullptr) {
239 if (set_remote_values) {
251 this->
transformer_ = make_unique<LightFlashTransformer>(*this);
254 if (set_remote_values) {
263 if (set_remote_values) {
void current_values_as_rgbww(float *red, float *green, float *blue, float *cold_white, float *warm_white, bool constant_brightness=false)
float gamma_correct_
Gamma correction factor for the light.
ESPPreferenceObject rtc_
Object used to store the persisted values of the light.
void set_flash_transition_length(uint32_t flash_transition_length)
Set the flash transition length.
float get_warm_white() const
Get the warm white property of these light color values. In range 0.0 to 1.0.
uint32_t get_flash_transition_length() const
void publish_state()
Publish the currently active state to the frontend.
std::unique_ptr< LightTransformer > transformer_
The currently active transformer for this light (transition/flash).
void set_immediately_(const LightColorValues &target, bool set_remote_values)
Internal method to set the color values to target immediately (with no transition).
bool is_on() const
Get the binary true/false state of these light color values.
uint32_t default_transition_length_
Default transition length for all transitions in ms.
Interface to write LightStates to hardware.
LightColorValues current_values
The current values of the light as outputted to the light.
void set_default_transition_length(uint32_t default_transition_length)
Set the default transition length, i.e. the transition length when no transition is provided...
std::string get_effect_name()
Return the name of the current effect, or if no effect is active "None".
LightCall turn_on()
Make a light state call.
void start_transition_(const LightColorValues &target, uint32_t length, bool set_remote_values)
Internal method to start a transition to the target color with the given length.
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.
float get_cold_white() const
Get the cold white property of these light color values. In range 0.0 to 1.0.
void start_effect_(uint32_t effect_index)
Internal method to start an effect with the given index.
LightRestoreMode restore_mode_
Restore mode of the light.
LightOutput * get_output() const
Get the light output associated with this object.
float get_min_mireds() const
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.
bool supports_effects()
Return whether the light has any effects that meet the trait requirements.
void start_flash_(const LightColorValues &target, uint32_t length, bool set_remote_values)
Internal method to start a flash for the specified amount of time.
float get_red() const
Get the red property of these light color values. In range 0.0 to 1.0.
virtual std::unique_ptr< LightTransformer > create_default_transition()
Return the default transformer used for transitions.
void add_new_target_state_reached_callback(std::function< void()> &&send_callback)
The callback is called once the state of current_values and remote_values are equal (when the transit...
Color temperature can be controlled.
void setup() override
Load state from preferences.
void dump_config() override
void current_values_as_binary(bool *binary)
The result of all the current_values_as_* methods have gamma correction applied.
bool next_write_
Whether the light value should be written in the next cycle.
void current_values_as_rgb(float *red, float *green, float *blue, bool color_interlock=false)
float get_blue() const
Get the blue property of these light color values. In range 0.0 to 1.0.
uint32_t flash_transition_length_
Transition length to use for flash transitions.
LightState(LightOutput *output)
virtual void write_state(LightState *state)=0
Called from loop() every time the light state has changed, and should should write the new state to h...
LightOutput * output_
Store the output to allow effects to have more access.
float gamma_correct(float value, float gamma)
Applies gamma correction of gamma to value.
This class represents the color state for a light object.
void current_values_as_rgbct(float *red, float *green, float *blue, float *color_temperature, float *white_brightness)
LightEffect * get_active_effect_()
Internal method to get the currently active effect.
float get_white() const
Get the white property of these light color values. In range 0.0 to 1.0.
ESPPreferences * global_preferences
float get_color_temperature() const
Get the color temperature property of these light color values in mired.
void add_effects(const std::vector< LightEffect *> &effects)
Add effects for this light state.
void current_values_as_brightness(float *brightness)
uint32_t get_default_transition_length() const
void set_gamma_correct(float gamma_correct)
Set the gamma correction factor.
const std::vector< LightEffect * > & get_effects() const
Get all effects for this light state.
This class represents a requested change in a light state.
ColorMode get_color_mode() const
Get the color mode of these light color values.
LightCall & set_state(optional< bool > state)
Set the binary ON/OFF state of the light.
std::vector< LightEffect * > effects_
List of effects for this light.
Master brightness of the light can be controlled.
void current_values_as_ct(float *color_temperature, float *white_brightness)
void current_values_as_cwww(float *cold_white, float *warm_white, bool constant_brightness=false)
bool is_transformer_active_
float get_setup_priority() const override
Shortly after HARDWARE.
void set_initial_state(const LightStateRTCState &initial_state)
Set the initial state of this light.
CallbackManager< void()> remote_values_callback_
Callback to call when new values for the frontend are available.
virtual void update_state(LightState *state)
Called on every update of the current values of the associated LightState, can optionally be used to ...
This class is used to represent the capabilities of a light.
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.
void add_new_remote_values_callback(std::function< void()> &&send_callback)
This lets front-end components subscribe to light change events.
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.
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
void set_restore_mode(LightRestoreMode restore_mode)
Set the restore mode of this light.
virtual ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash)=0
void set_color_temperature(float color_temperature)
Set the color temperature property of these light color values in mired.
void save_remote_values_()
Internal method to save the current remote_values to the preferences.
void as_binary(bool *binary) const
Convert these light color values to a binary representation and write them to binary.
virtual void setup_state(LightState *state)
CallbackManager< void()> target_state_reached_callback_
Callback to call when the state of current_values and remote_values are equal This should be called o...
Implementation of SPI Controller mode.
optional< LightStateRTCState > initial_state_
Initial state of the light.
uint32_t active_effect_index_
Value for storing the index of the currently active effect. 0 if no effect is active.
LightColorValues remote_values
The remote color values reported to the frontend.
virtual LightTraits get_traits()=0
Return the LightTraits of this LightOutput.
float get_color_brightness() const
Get the color brightness property of these light color values. In range 0.0 to 1.0.
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...
bool is_transformer_active()
Indicator if a transformer (e.g.
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.
void as_brightness(float *brightness, float gamma=0) const
Convert these light color values to a brightness-only representation and write them to brightness...
void stop_effect_()
Internal method to stop the current effect (if one is active).
uint32_t get_object_id_hash()
float get_green() const
Get the green property of these light color values. In range 0.0 to 1.0.
const StringRef & get_name() const
float get_brightness() const
Get the brightness property of these light color values. In range 0.0 to 1.0.
void current_values_as_rgbw(float *red, float *green, float *blue, float *white, bool color_interlock=false)