ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
template_switch.h
Go to the documentation of this file.
1#pragma once
2
7
8namespace esphome::template_ {
9
10class TemplateSwitch final : public switch_::Switch, public Component {
11 public:
13
14 void setup() override;
15 void dump_config() override;
16
17 template<typename F> void set_state_lambda(F &&f) { this->f_.set(std::forward<F>(f)); }
20 void set_optimistic(bool optimistic) { this->optimistic_ = optimistic; }
22 void loop() override;
23
24 float get_setup_priority() const override;
25
26 protected:
27 bool assumed_state() override;
28
29 void write_state(bool state) override;
30
32 // Codegen only emits these setters to turn them on
33 bool optimistic_{false};
34 bool assumed_state_{false};
37 Trigger<> *prev_trigger_{nullptr}; // Points to one of the above
38};
39
40} // namespace esphome::template_
Lightweight wrapper for template platform lambdas (stateless function pointers only).
void set(optional< T >(*f)(Args...))
Set the lambda function pointer.
Base class for all switches.
Definition switch.h:43
bool state
The current reported state of the binary sensor.
Definition switch.h:60
float get_setup_priority() const override
void write_state(bool state) override
void set_assumed_state(bool assumed_state)
void set_optimistic(bool optimistic)