ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
lvgl_switch.h
Go to the documentation of this file.
1#pragma once
2
3#include <utility>
4
9
10namespace esphome::lvgl {
11
12class LVGLSwitch : public switch_::Switch, public Component {
13 public:
14 LVGLSwitch(std::function<void(bool)> state_lambda) : state_lambda_(std::move(state_lambda)) {}
15
16 void setup() override { this->write_state(this->get_initial_state_with_restore_mode().value_or(false)); }
17
18 protected:
19 void write_state(bool value) override { this->state_lambda_(value); }
20 std::function<void(bool)> state_lambda_{};
21};
22
23} // namespace esphome::lvgl
void setup() override
Definition lvgl_switch.h:16
std::function< void(bool)> state_lambda_
Definition lvgl_switch.h:20
LVGLSwitch(std::function< void(bool)> state_lambda)
Definition lvgl_switch.h:14
void write_state(bool value) override
Definition lvgl_switch.h:19
Base class for all switches.
Definition switch.h:38
optional< bool > get_initial_state_with_restore_mode()
Returns the initial state of the switch, after applying restore mode rules.
Definition switch.cpp:42