ESPHome  2022.11.3
safe_mode_switch.cpp
Go to the documentation of this file.
1 #include "safe_mode_switch.h"
2 #include "esphome/core/hal.h"
3 #include "esphome/core/log.h"
5 
6 namespace esphome {
7 namespace safe_mode {
8 
9 static const char *const TAG = "safe_mode_switch";
10 
11 void SafeModeSwitch::set_ota(ota::OTAComponent *ota) { this->ota_ = ota; }
12 
14  // Acknowledge
15  this->publish_state(false);
16 
17  if (state) {
18  ESP_LOGI(TAG, "Restarting device in safe mode...");
19  this->ota_->set_safe_mode_pending(true);
20 
21  // Let MQTT settle a bit
22  delay(100); // NOLINT
23  App.safe_reboot();
24  }
25 }
26 void SafeModeSwitch::dump_config() { LOG_SWITCH("", "Safe Mode Switch", this); }
27 
28 } // namespace safe_mode
29 } // namespace esphome
void write_state(bool state) override
Application App
Global storage of Application pointer - only one Application can exist.
void set_ota(ota::OTAComponent *ota)
Definition: a4988.cpp:4
void set_safe_mode_pending(const bool &pending)
Set to true if the next startup will enter safe mode.
void publish_state(bool state)
Publish a state to the front-end from the back-end.
Definition: switch.cpp:31
bool state
The current reported state of the binary sensor.
Definition: switch.h:48
OTAComponent provides a simple way to integrate Over-the-Air updates into your app using ArduinoOTA...
Definition: ota_component.h:43
void IRAM_ATTR HOT delay(uint32_t ms)
Definition: core.cpp:27