ESPHome 2026.10.2
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); }
9void OutputSwitch::setup() { this->control(this->get_initial_state_with_restore_mode().value_or(false)); }
11 this->output_->set_state(state);
12 this->publish_state(state);
13}
14
15} // namespace esphome::output
virtual void set_state(bool state)
Enable or disable this binary output.
void write_state(bool state) override
output::BinaryOutput * output_
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
void control(bool target_state)
Control this switch using a boolean state value.
Definition switch.cpp:12
bool state
Definition fan.h:2