ESPHome  2024.12.2
restart_switch.cpp
Go to the documentation of this file.
1 #include "restart_switch.h"
2 #include "esphome/core/hal.h"
3 #include "esphome/core/log.h"
5 
6 namespace esphome {
7 namespace restart {
8 
9 static const char *const TAG = "restart";
10 
12  // Acknowledge
13  this->publish_state(false);
14 
15  if (state) {
16  ESP_LOGI(TAG, "Restarting device...");
17  // Let MQTT settle a bit
18  delay(100); // NOLINT
19  App.safe_reboot();
20  }
21 }
22 void RestartSwitch::dump_config() { LOG_SWITCH("", "Restart Switch", this); }
23 
24 } // namespace restart
25 } // namespace esphome
void write_state(bool state) override
Application App
Global storage of Application pointer - only one Application can exist.
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
Definition: fan.h:34
void IRAM_ATTR HOT delay(uint32_t ms)
Definition: core.cpp:26