ESPHome  2024.12.2
switch.cpp
Go to the documentation of this file.
1 #include "switch.h"
2 
3 namespace esphome {
4 namespace opentherm {
5 
6 static const char *const TAG = "opentherm.switch";
7 
8 void OpenthermSwitch::write_state(bool state) { this->publish_state(state); }
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
void write_state(bool state) override
Definition: switch.cpp:8
optional< bool > get_initial_state_with_restore_mode()
Returns the initial state of the switch, after applying restore mode rules.
Definition: switch.cpp:33
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void publish_state(bool state)
Publish a state to the front-end from the back-end.
Definition: switch.cpp:47
bool state
The current reported state of the binary sensor.
Definition: switch.h:53
const StringRef & get_name() const
Definition: entity_base.cpp:10
bool state
Definition: fan.h:34