ESPHome  2024.2.1
factory_reset_switch.cpp
Go to the documentation of this file.
1 #include "factory_reset_switch.h"
2 #include "esphome/core/hal.h"
3 #include "esphome/core/log.h"
5 
6 namespace esphome {
7 namespace factory_reset {
8 
9 static const char *const TAG = "factory_reset.switch";
10 
11 void FactoryResetSwitch::dump_config() { LOG_SWITCH("", "Factory Reset Switch", this); }
13  // Acknowledge
14  this->publish_state(false);
15 
16  if (state) {
17  ESP_LOGI(TAG, "Resetting to factory defaults...");
18  // Let MQTT settle a bit
19  delay(100); // NOLINT
21  App.safe_reboot();
22  }
23 }
24 
25 } // namespace factory_reset
26 } // namespace esphome
ESPPreferences * global_preferences
virtual bool reset()=0
Forget all unsaved changes and re-initialize the permanent preferences storage.
Application App
Global storage of Application pointer - only one Application can exist.
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 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