ESPHome 2025.5.0
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 ESP_LOGCONFIG(TAG, "Setting up Output Switch '%s'...", this->name_.c_str());
12
13 bool initial_state = this->get_initial_state_with_restore_mode().value_or(false);
14
15 if (initial_state) {
16 this->turn_on();
17 } else {
18 this->turn_off();
19 }
20}
22 if (state) {
23 this->output_->turn_on();
24 } else {
25 this->output_->turn_off();
26 }
27 this->publish_state(state);
28}
29
30} // namespace output
31} // namespace esphome
constexpr const char * c_str() const
Definition string_ref.h:68
value_type value_or(U const &v) const
Definition optional.h:93
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:11
void turn_off()
Turn this switch off.
Definition switch.cpp:15
void publish_state(bool state)
Publish a state to the front-end from the back-end.
Definition switch.cpp:47
optional< bool > get_initial_state_with_restore_mode()
Returns the initial state of the switch, after applying restore mode rules.
Definition switch.cpp:33
bool state
Definition fan.h:0
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7