83#ifdef USE_LIGHT_TRANSITION_PUBLISH_INTERVAL
98 void setup()
override;
100 void loop()
override;
155#ifdef USE_LIGHT_FLASH_TRANSITION_LENGTH
163 ESPDEPRECATED(
"set_flash_transition_length() does nothing unless flash_transition_length is set in YAML. Removed in "
171 ESPDEPRECATED(
"set_gamma_correct() does nothing; gamma is fixed at build time by gamma_correct in YAML. Removed in "
174 void set_gamma_correct(
float gamma_correct) {}
178#ifdef USE_LIGHT_TRANSITION_PUBLISH_INTERVAL
185#ifdef USE_LIGHT_GAMMA_LUT
211#ifdef USE_LIGHT_RESUME_EFFECT
223 void add_effects(
const std::initializer_list<LightEffect *> &effects);
236 for (
size_t i = 0; i < this->
effects_.size(); i++) {
246 if (
len == 4 && ESPHOME_strncasecmp_P(name, ESPHOME_PSTR(
"none"), 4) == 0) {
250 for (
size_t i = 0; i < this->
effects_.size(); i++) {
260 if (index == 0 || index > this->
effects_.size()) {
271 if (index > this->
effects_.size()) {
287 bool constant_brightness =
false);
290 float *white_brightness);
330#ifdef USE_LIGHT_TRANSITION_PUBLISH_INTERVAL
334 if (set_remote_values) {
335 this->remote_values = target;
386#ifdef USE_LIGHT_FLASH_TRANSITION_LENGTH
390#ifdef USE_LIGHT_TRANSITION_PUBLISH_INTERVAL
394#ifdef USE_LIGHT_GAMMA_LUT
400#ifdef USE_LIGHT_RESUME_EFFECT
405 bool next_write_{true};
410#ifdef USE_LIGHT_TRANSITION_PUBLISH_INTERVAL
414#ifdef USE_LIGHT_RESUME_EFFECT
void enable_loop()
Enable this component's loop.
const StringRef & get_name() const
Fixed-capacity vector - sized once through init() or try_init(); push_back never reallocates This avo...
StringRef is a reference to a string owned by something else.
This class represents a requested change in a light state.
This class represents the color state for a light object.
void as_binary(bool *binary) const
Convert these light color values to a binary representation and write them to binary.
Interface to write LightStates to hardware.
Listener interface for light remote value changes.
virtual void on_light_remote_values_update()=0
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
void add_remote_values_listener(LightRemoteValuesListener *listener)
Add a listener for remote values changes.
uint32_t get_transition_state_publish_interval() const
FixedVector< LightEffect * > effects_
List of effects for this light.
StringRef get_effect_name()
Return the name of the current effect, or if no effect is active "None".
bool resume_effect_
Whether a plain turn-on restores the effect that was active when the light was turned off.
void start_effect_(uint32_t effect_index)
Internal method to start an effect with the given index.
void current_values_as_rgb(float *red, float *green, float *blue)
std::string get_effect_name_by_index(uint32_t index) const
Get effect name by index. Returns "None" for index 0, empty string for invalid index.
float gamma_correct_lut(float value) const
Apply gamma correction using the pre-computed forward LUT.
void stop_effect_()
Internal method to stop the current effect (if one is active).
bool supports_effects() const
Return whether the light has any effects that meet the trait requirements.
void current_values_as_rgbct(float *red, float *green, float *blue, float *color_temperature, float *white_brightness)
void disable_loop_if_idle_()
Disable loop if neither transformer nor effect is active.
std::unique_ptr< LightTransformer > transformer_
The currently active transformer for this light (transition/flash).
void set_save_enabled(bool save_enabled)
Set whether this light persists its state to preferences at all.
void dump_config() override
bool transition_publish_enabled_
True while the active transformer publishes current_values on an interval from loop().
LightColorValues remote_values
The remote color values reported to the frontend.
uint32_t get_current_effect_index() const
Get the currently active effect index (0 = no effect, 1+ = effect index).
LightOutput * get_output() const
Get the light output associated with this object.
const LightColorValues & get_reported_values() const
The values reported to the frontend: current_values while a light publishes intermediate states on an...
void set_flash_transition_length(uint32_t flash_transition_length)
Set the flash transition length; only compiled in when a light configures one.
ESPDEPRECATED("set_flash_transition_length() does nothing unless flash_transition_length is set in YAML. Removed in " "2027.4.0", "2026.10.0") void set_flash_transition_length(uint32_t flash_transition_length)
void(* state_callback_)(LightStateRTCState &, bool restored)
Callback that resolves the boot-time state — called once during setup, then cleared.
LightState(LightOutput *output)
void current_values_as_binary(bool *binary)
The result of all the current_values_as_* methods have gamma correction applied.
void save_remote_values_()
Internal method to save the current remote_values to the preferences.
void add_target_state_reached_listener(LightTargetStateReachedListener *listener)
Add a listener for target state reached.
LightCall turn_on()
Make a light state call.
uint32_t get_default_transition_length() const
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_transitioning() const
True from the call that starts a transition or flash until it reaches its target.
uint32_t get_flash_transition_length() const
ESPDEPRECATED("set_gamma_correct() does nothing; gamma is fixed at build time by gamma_correct in YAML. Removed in " "2027.4.0", "2026.10.0") void set_gamma_correct(float gamma_correct)
float get_gamma_correct() const
The gamma correction factor, read from the entry after the gamma lookup table; 0 without one.
uint32_t get_effect_index(const std::string &effect_name) const
Get effect index by name. Returns 0 if effect not found.
void current_values_as_ct(float *color_temperature, float *white_brightness)
float gamma_uncorrect_lut(float value) const
Reverse gamma correction by binary-searching the forward LUT.
void current_values_as_cwww(float *cold_white, float *warm_white, bool constant_brightness=false)
uint32_t flash_transition_length_
Transition length to use for flash transitions.
void publish_state()
Publish the currently active state to the frontend.
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_brightness(float *brightness)
void setup() override
Load state from preferences.
LightEffect * get_effect_by_index(uint32_t index) const
Get effect by index. Returns nullptr if index is invalid.
const GammaTable * gamma_table_
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.
void set_resume_effect(bool resume_effect)
Set whether a plain turn-on restores the effect that was active when the light was turned off.
bool is_transformer_active() const
Indicator if a transformer (e.g.
const FixedVector< LightEffect * > & get_effects() const
Get all effects for this light state.
void set_transition_state_publish_interval(uint32_t transition_state_publish_interval)
uint32_t transition_state_publish_interval_
void add_effects(const std::initializer_list< LightEffect * > &effects)
Add effects for this light state.
void schedule_write_()
Schedule a write to the light output and enable the loop to process it.
uint16_t previous_effect_index_
The effect index that was active when the light was last turned off; shares the active index's word.
const uint16_t * get_gamma_table() const
Get the forward gamma lookup table, 256 PROGMEM entries.
bool next_write_
Whether the light value should be written in the next cycle.
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.
bool save_enabled_
Whether this light persists its state to preferences at all.
float get_setup_priority() const override
Shortly after HARDWARE.
LightOutput * output_
Store the output to allow effects to have more access.
ESPPreferenceObject rtc_
Object used to store the persisted values of the light.
uint16_t active_effect_index_
1-based index of the active effect, 0 if none; codegen caps effects at MAX_EFFECTS in effects....
void current_values_as_rgbw(float *red, float *green, float *blue, float *white)
uint32_t default_transition_length_
Default transition length for all transitions in ms.
void set_gamma_table(const GammaTable *table)
Set the pre-computed PROGMEM gamma curve.
void set_state_callback(void(*callback)(LightStateRTCState &, bool restored))
Set the callback that resolves the boot-time state, called once during setup then cleared.
LightColorValues current_values
The current values of the light as outputted to the light.
uint32_t get_effect_index(const char *name, size_t len) const
Get effect index by name (const char* overload, avoids std::string construction).
LightEffect * get_active_effect_()
Internal method to get the currently active effect.
size_t get_effect_count() const
Get the total number of effects available for this light.
bool is_transformer_active_
std::unique_ptr< std::vector< LightRemoteValuesListener * > > remote_values_listeners_
Listeners for remote values changes.
std::unique_ptr< std::vector< LightTargetStateReachedListener * > > target_state_reached_listeners_
Listeners for target state reached.
uint32_t last_transition_state_publish_
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.
void set_transformer_remote_values_(const LightColorValues &target, bool set_remote_values)
Point remote_values at the new transformer's target and, when this light publishes intermediate state...
Listener interface for light target state reached.
virtual void on_light_target_state_reached()=0
This class is used to represent the capabilities of a light.
ColorMode
Color modes are a combination of color capabilities that can be used at the same time.
@ UNKNOWN
No color mode configured (cannot be a supported mode, only active when light is off).
constexpr float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
bool str_equals_case_insensitive(const std::string &a, const std::string &b)
Compare strings for equality in case-insensitive manner.
A gamma curve as codegen emits it into PROGMEM: the lookup table and the gamma it was built from.