mirror of
https://github.com/esphome/esphome.git
synced 2025-04-13 14:20:29 +01:00
* Add macros header with more usable Arduino version defines * Change Arduino version checking to use our version defines * Add missing ESP8266 check * Rename Arduino version macro to ARDUINO_VERSION_CODE * Upgrade clang-tidy to use Arduino 3 * Fix clang-tidy warnings * Upgrade NeoPixelBus to upstream 2.6.7 * Use Arduino-version-appropriate API to set redirect flags * Remove now unnecessary CLANG_TIDY ifdefs * Add preprocessor hackery to avoid including pgmspace.h * Bump base image to 4.1.1 and update lint * Fix nfctag * Fix make_unique ambiguous * Fix ignore name * Fix ambiguous v2 * Remove unused begin * Cast time_t to prevent issues on platforms where time_t is 32bit Co-authored-by: Otto winter <otto@otto-winter.com>
31 lines
714 B
C++
31 lines
714 B
C++
#include "shutdown_switch.h"
|
|
#include "esphome/core/log.h"
|
|
#include "esphome/core/application.h"
|
|
|
|
namespace esphome {
|
|
namespace shutdown {
|
|
|
|
static const char *const TAG = "shutdown.switch";
|
|
|
|
void ShutdownSwitch::dump_config() { LOG_SWITCH("", "Shutdown Switch", this); }
|
|
void ShutdownSwitch::write_state(bool state) {
|
|
// Acknowledge
|
|
this->publish_state(false);
|
|
|
|
if (state) {
|
|
ESP_LOGI(TAG, "Shutting down...");
|
|
delay(100); // NOLINT
|
|
|
|
App.run_safe_shutdown_hooks();
|
|
#ifdef ARDUINO_ARCH_ESP8266
|
|
ESP.deepSleep(0); // NOLINT(readability-static-accessed-through-instance)
|
|
#endif
|
|
#ifdef ARDUINO_ARCH_ESP32
|
|
esp_deep_sleep_start();
|
|
#endif
|
|
}
|
|
}
|
|
|
|
} // namespace shutdown
|
|
} // namespace esphome
|