ESPHome  2022.6.2
template_switch.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 namespace esphome {
8 namespace template_ {
9 
10 class TemplateSwitch : public switch_::Switch, public Component {
11  public:
13 
14  void setup() override;
15  void dump_config() override;
16 
17  void set_state_lambda(std::function<optional<bool>()> &&f);
18  void set_restore_state(bool restore_state);
21  void set_optimistic(bool optimistic);
23  void loop() override;
24 
25  float get_setup_priority() const override;
26 
27  protected:
28  bool assumed_state() override;
29 
30  void write_state(bool state) override;
31 
33  bool optimistic_{false};
34  bool assumed_state_{false};
38  bool restore_state_{false};
39 };
40 
41 } // namespace template_
42 } // namespace esphome
Base class for all switches.
Definition: switch.h:33
void set_restore_state(bool restore_state)
void set_state_lambda(std::function< optional< bool >()> &&f)
void set_optimistic(bool optimistic)
void write_state(bool state) override
optional< std::function< optional< bool >)> > f_
Definition: a4988.cpp:4
void set_assumed_state(bool assumed_state)
float get_setup_priority() const override
bool state
The current reported state of the binary sensor.
Definition: switch.h:48