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