ESPHome  2024.3.1
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)
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
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:47
bool state
The current reported state of the binary sensor.
Definition: switch.h:53
OTAComponent provides a simple way to integrate Over-the-Air updates into your app using ArduinoOTA...
Definition: ota_component.h:44
void IRAM_ATTR HOT delay(uint32_t ms)
Definition: core.cpp:26