Uncouple safe_mode from OTA (#6759)

This commit is contained in:
Keith Burzinski
2024-05-21 20:08:53 -05:00
committed by GitHub
parent 83d3584173
commit 76abf2200c
21 changed files with 282 additions and 200 deletions
@@ -6,9 +6,11 @@
namespace esphome {
namespace safe_mode {
static const char *const TAG = "safe_mode_switch";
static const char *const TAG = "safe_mode.switch";
void SafeModeSwitch::set_ota(esphome::ESPHomeOTAComponent *ota) { this->ota_ = ota; }
void SafeModeSwitch::set_safe_mode(SafeModeComponent *safe_mode_component) {
this->safe_mode_component_ = safe_mode_component;
}
void SafeModeSwitch::write_state(bool state) {
// Acknowledge
@@ -16,13 +18,14 @@ void SafeModeSwitch::write_state(bool state) {
if (state) {
ESP_LOGI(TAG, "Restarting device in safe mode...");
this->ota_->set_safe_mode_pending(true);
this->safe_mode_component_->set_safe_mode_pending(true);
// Let MQTT settle a bit
delay(100); // NOLINT
App.safe_reboot();
}
}
void SafeModeSwitch::dump_config() { LOG_SWITCH("", "Safe Mode Switch", this); }
} // namespace safe_mode