ESPHome 2025.9.0-dev
Loading...
Searching...
No Matches
output_switch.cpp
Go to the documentation of this file.
1#include "output_switch.h"
2#include "esphome/core/log.h"
3
4namespace esphome {
5namespace output {
6
7static const char *const TAG = "output.switch";
8
9void OutputSwitch::dump_config() { LOG_SWITCH("", "Output Switch", this); }
11 bool initial_state = this->get_initial_state_with_restore_mode().value_or(false);
12
13 if (initial_state) {
14 this->turn_on();
15 } else {
16 this->turn_off();
17 }
18}
20 if (state) {
21 this->output_->turn_on();
22 } else {
23 this->output_->turn_off();
24 }
25 this->publish_state(state);
26}
27
28} // namespace output
29} // namespace esphome
value_type value_or(U const &v) const
Definition optional.h:98
virtual void turn_off()
Disable this binary output.
virtual void turn_on()
Enable this binary output.
void write_state(bool state) override
output::BinaryOutput * output_
void turn_on()
Turn this switch on.
Definition switch.cpp:19
void turn_off()
Turn this switch off.
Definition switch.cpp:23
void publish_state(bool state)
Publish a state to the front-end from the back-end.
Definition switch.cpp:55
optional< bool > get_initial_state_with_restore_mode()
Returns the initial state of the switch, after applying restore mode rules.
Definition switch.cpp:41
bool state
Definition fan.h:0
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7