ESPHome  2024.11.0
shutdown_switch.cpp
Go to the documentation of this file.
1 #include "shutdown_switch.h"
2 #include "esphome/core/hal.h"
3 #include "esphome/core/log.h"
5 
6 #ifdef USE_ESP32
7 #include <esp_sleep.h>
8 #endif
9 #ifdef USE_ESP8266
10 #include <Esp.h>
11 #endif
12 
13 namespace esphome {
14 namespace shutdown {
15 
16 static const char *const TAG = "shutdown.switch";
17 
18 void ShutdownSwitch::dump_config() { LOG_SWITCH("", "Shutdown Switch", this); }
20  // Acknowledge
21  this->publish_state(false);
22 
23  if (state) {
24  ESP_LOGI(TAG, "Shutting down...");
25  delay(100); // NOLINT
26 
28 #ifdef USE_ESP8266
29  ESP.deepSleep(0); // NOLINT(readability-static-accessed-through-instance)
30 #endif
31 #ifdef USE_ESP32
32  esp_deep_sleep_start();
33 #endif
34  }
35 }
36 
37 } // namespace shutdown
38 } // 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
The current reported state of the binary sensor.
Definition: switch.h:53
void IRAM_ATTR HOT delay(uint32_t ms)
Definition: core.cpp:26