ESPHome 2025.5.0
Loading...
Searching...
No Matches
switch.cpp
Go to the documentation of this file.
1#include "switch.h"
2
3namespace esphome {
4namespace opentherm {
5
6static const char *const TAG = "opentherm.switch";
7
9
11 auto restored = this->get_initial_state_with_restore_mode();
12 bool state = false;
13 if (!restored.has_value()) {
14 ESP_LOGD(TAG, "Couldn't restore state for OpenTherm switch '%s'", this->get_name().c_str());
15 } else {
16 ESP_LOGD(TAG, "Restored state for OpenTherm switch '%s': %d", this->get_name().c_str(), restored.value());
17 state = restored.value();
18 }
19 this->write_state(state);
20}
21
23 LOG_SWITCH("", "OpenTherm Switch", this);
24 ESP_LOGCONFIG(TAG, " Current state: %d", this->state);
25}
26
27} // namespace opentherm
28} // namespace esphome
const StringRef & get_name() const
void write_state(bool state) override
Definition switch.cpp:8
bool state
The current reported state of the binary sensor.
Definition switch.h:53
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