ESPHome 2025.5.0
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 {
11namespace lvgl {
12
13class 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
void setup() override
Definition lvgl_switch.h:17
std::function< void(bool)> state_lambda_
Definition lvgl_switch.h:21
LVGLSwitch(std::function< void(bool)> state_lambda)
Definition lvgl_switch.h:15
void write_state(bool value) override
Definition lvgl_switch.h:20
Base class for all switches.
Definition switch.h:39
optional< bool > get_initial_state_with_restore_mode()
Returns the initial state of the switch, after applying restore mode rules.
Definition switch.cpp:33
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7