ESPHome 2026.5.0b1
Loading...
Searching...
No Matches
lvgl_light.h
Go to the documentation of this file.
1#pragma once
2
5#include "../lvgl_esphome.h"
6
7namespace esphome::lvgl {
8
9class LVLight : public light::LightOutput {
10 public:
12 auto traits = light::LightTraits();
13 traits.set_supported_color_modes({light::ColorMode::RGB});
14 return traits;
15 }
17 float red, green, blue;
18 state->current_values_as_rgb(&red, &green, &blue);
19 auto color = lv_color_make(red * 255, green * 255, blue * 255);
20 if (this->obj_ != nullptr) {
21 this->set_value_(color);
22 } else {
23 this->initial_value_ = color;
24 }
25 }
26
27 void set_obj(lv_obj_t *obj) {
28 this->obj_ = obj;
29 if (this->initial_value_) {
30 lv_led_set_color(obj, this->initial_value_.value());
31 lv_led_on(obj);
32 this->initial_value_.reset();
33 }
34 }
35
36 protected:
37 void set_value_(lv_color_t value) {
38 lv_led_set_color(this->obj_, value);
39 lv_led_on(this->obj_);
40 lv_obj_send_event(this->obj_, lv_update_event, nullptr);
41 }
42 lv_obj_t *obj_{};
43 optional<lv_color_t> initial_value_{};
44};
45
46} // namespace esphome::lvgl
Interface to write LightStates to hardware.
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition light_state.h:93
This class is used to represent the capabilities of a light.
Definition light_traits.h:9
light::LightTraits get_traits() override
Definition lvgl_light.h:11
optional< lv_color_t > initial_value_
Definition lvgl_light.h:43
void set_obj(lv_obj_t *obj)
Definition lvgl_light.h:27
void write_state(light::LightState *state) override
Definition lvgl_light.h:16
void set_value_(lv_color_t value)
Definition lvgl_light.h:37
bool state
Definition fan.h:2
@ RGB
RGB color output.
lv_event_code_t lv_update_event