ESPHome 2026.6.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::output {
5
6static const char *const TAG = "output.switch";
7
8void OutputSwitch::dump_config() { LOG_SWITCH("", "Output Switch", this); }
10 bool initial_state = this->get_initial_state_with_restore_mode().value_or(false);
11
12 if (initial_state) {
13 this->turn_on();
14 } else {
15 this->turn_off();
16 }
17}
19 if (state) {
20 this->output_->turn_on();
21 } else {
22 this->output_->turn_off();
23 }
24 this->publish_state(state);
25}
26
27} // namespace esphome::output
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:20
void turn_off()
Turn this switch off.
Definition switch.cpp:24
void publish_state(bool state)
Publish a state to the front-end from the back-end.
Definition switch.cpp:56
optional< bool > get_initial_state_with_restore_mode()
Returns the initial state of the switch, after applying restore mode rules.
Definition switch.cpp:42
bool state
Definition fan.h:2