ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
light_effect.h
Go to the documentation of this file.
1#pragma once
2
5
6namespace esphome::light {
7
8inline constexpr StringRef EFFECT_NONE_REF = StringRef::from_lit("None");
9
10class LightState;
11
13 public:
14 explicit LightEffect(const char *name) : name_(name) {}
15
17 virtual void start() {}
18
19 virtual void start_internal() { this->start(); }
20
22 virtual void stop() {}
23
25 virtual void apply() = 0;
26
31 StringRef get_name() const { return StringRef(this->name_); }
32
34 virtual void init() {}
35
37 this->state_ = state;
38 this->init();
39 }
40
43 uint32_t get_index() const;
44
46 bool is_active() const;
47
50 LightState *get_light_state() const { return this->state_; }
51
52 protected:
53 LightState *state_{nullptr};
54 const char *name_;
55
58};
59
60} // namespace esphome::light
StringRef is a reference to a string owned by something else.
Definition string_ref.h:31
static constexpr StringRef from_lit(const CharT(&s)[N])
Definition string_ref.h:55
uint32_t get_index_in_parent_() const
Internal method to find this effect's index in the parent light's effect list.
LightEffect(const char *name)
virtual void init()
Internal method called by the LightState when this light effect is registered in it.
virtual void start()
Initialize this LightEffect. Will be called once after creation.
uint32_t get_index() const
Get the index of this effect in the parent light's effect list.
StringRef get_name() const
Returns the name of this effect.
virtual void apply()=0
Apply this effect. Use the provided state for starting transitions, ...
LightState * get_light_state() const
Get a reference to the parent light state.
virtual void stop()
Called when this effect is about to be removed.
virtual void start_internal()
void init_internal(LightState *state)
bool is_active() const
Check if this effect is currently active.
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition light_state.h:68
bool state
Definition fan.h:2
constexpr StringRef EFFECT_NONE_REF
Definition light_effect.h:8