ESPHome 2026.2.1
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);
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 bool optimistic_{false};
33 bool assumed_state_{false};
36 Trigger<> *prev_trigger_{nullptr}; // Points to one of the above
37};
38
39} // namespace esphome::template_
ESPDEPRECATED("set_retry is deprecated and will be removed in 2026.8.0. Use set_timeout or set_interval instead.", "2026.2.0") void set_retry(const std uint32_t uint8_t std::function< RetryResult(uint8_t)> && f
Definition component.h:373
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:39
bool state
The current reported state of the binary sensor.
Definition switch.h:56
float get_setup_priority() const override
void write_state(bool state) override
void set_assumed_state(bool assumed_state)