ESPHome  2025.3.3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
lvgl_switch.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <utility>
4 
9 
10 namespace esphome {
11 namespace lvgl {
12 
13 class LVGLSwitch : public switch_::Switch, public Component {
14  public:
15  LVGLSwitch(std::function<void(bool)> state_lambda) : state_lambda_(std::move(state_lambda)) {}
16 
17  void setup() override { this->write_state(this->get_initial_state_with_restore_mode().value_or(false)); }
18 
19  protected:
20  void write_state(bool value) override { this->state_lambda_(value); }
21  std::function<void(bool)> state_lambda_{};
22 };
23 
24 } // namespace lvgl
25 } // namespace esphome
Base class for all switches.
Definition: switch.h:39
std::function< void(bool)> state_lambda_
Definition: lvgl_switch.h:21
STL namespace.
optional< bool > get_initial_state_with_restore_mode()
Returns the initial state of the switch, after applying restore mode rules.
Definition: switch.cpp:33
LVGLSwitch(std::function< void(bool)> state_lambda)
Definition: lvgl_switch.h:15
void setup() override
Definition: lvgl_switch.h:17
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void write_state(bool value) override
Definition: lvgl_switch.h:20