mirror of
https://github.com/esphome/esphome.git
synced 2025-03-27 21:18:18 +00:00
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Co-authored-by: Jos Suanet <jos@suanet.net>
34 lines
757 B
C++
34 lines
757 B
C++
#include "shutdown_button.h"
|
|
#include "esphome/core/hal.h"
|
|
#include "esphome/core/log.h"
|
|
#include "esphome/core/application.h"
|
|
|
|
#ifdef USE_ESP32
|
|
#include <esp_sleep.h>
|
|
#endif
|
|
#ifdef USE_ESP8266
|
|
#include <Esp.h>
|
|
#endif
|
|
|
|
namespace esphome {
|
|
namespace shutdown {
|
|
|
|
static const char *const TAG = "shutdown.button";
|
|
|
|
void ShutdownButton::dump_config() { LOG_BUTTON("", "Shutdown Button", this); }
|
|
void ShutdownButton::press_action() {
|
|
ESP_LOGI(TAG, "Shutting down...");
|
|
// Let MQTT settle a bit
|
|
delay(100); // NOLINT
|
|
App.run_safe_shutdown_hooks();
|
|
#ifdef USE_ESP8266
|
|
ESP.deepSleep(0); // NOLINT(readability-static-accessed-through-instance)
|
|
#endif
|
|
#ifdef USE_ESP32
|
|
esp_deep_sleep_start();
|
|
#endif
|
|
}
|
|
|
|
} // namespace shutdown
|
|
} // namespace esphome
|