Add shutdown and safe_mode button (#2918)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
Co-authored-by: Jos Suanet <jos@suanet.net>
This commit is contained in:
jsuanet
2021-12-20 22:25:36 +01:00
committed by GitHub
parent 4907e6f6d7
commit f431c7402f
13 changed files with 164 additions and 4 deletions
@@ -0,0 +1,25 @@
#include "safe_mode_button.h"
#include "esphome/core/hal.h"
#include "esphome/core/log.h"
#include "esphome/core/application.h"
namespace esphome {
namespace safe_mode {
static const char *const TAG = "safe_mode.button";
void SafeModeButton::set_ota(ota::OTAComponent *ota) { this->ota_ = ota; }
void SafeModeButton::press_action() {
ESP_LOGI(TAG, "Restarting device in safe mode...");
this->ota_->set_safe_mode_pending(true);
// Let MQTT settle a bit
delay(100); // NOLINT
App.safe_reboot();
}
void SafeModeButton::dump_config() { LOG_BUTTON("", "Safe Mode Button", this); }
} // namespace safe_mode
} // namespace esphome