ESPHome  2024.11.0
safe_mode_switch.cpp
Go to the documentation of this file.
1 #include "safe_mode_switch.h"
3 #include "esphome/core/hal.h"
4 #include "esphome/core/log.h"
5 
6 namespace esphome {
7 namespace safe_mode {
8 
9 static const char *const TAG = "safe_mode.switch";
10 
12  this->safe_mode_component_ = safe_mode_component;
13 }
14 
16  // Acknowledge
17  this->publish_state(false);
18 
19  if (state) {
20  ESP_LOGI(TAG, "Restarting device in safe mode...");
22 
23  // Let MQTT settle a bit
24  delay(100); // NOLINT
25  App.safe_reboot();
26  }
27 }
28 
29 void SafeModeSwitch::dump_config() { LOG_SWITCH("", "Safe Mode Switch", this); }
30 
31 } // namespace safe_mode
32 } // namespace esphome
void write_state(bool state) override
SafeModeComponent * safe_mode_component_
void set_safe_mode_pending(const bool &pending)
Set to true if the next startup will enter safe mode.
Definition: safe_mode.cpp:47
Application App
Global storage of Application pointer - only one Application can exist.
void set_safe_mode(SafeModeComponent *safe_mode_component)
SafeModeComponent provides a safe way to recover from repeated boot failures.
Definition: safe_mode.h:12
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
void IRAM_ATTR HOT delay(uint32_t ms)
Definition: core.cpp:26