mirror of
https://github.com/esphome/esphome.git
synced 2026-02-08 08:41:59 +00:00
[safe_mode] Remove unnecessary blocking sync from successful boot reset
This commit is contained in:
@@ -69,7 +69,6 @@ void SafeModeComponent::set_safe_mode_pending(const bool &pending) {
|
||||
if (pending && current_rtc != SafeModeComponent::ENTER_SAFE_MODE_MAGIC) {
|
||||
ESP_LOGI(TAG, "Device will enter on next boot");
|
||||
this->write_rtc_(SafeModeComponent::ENTER_SAFE_MODE_MAGIC);
|
||||
global_preferences->sync(); // Must persist before potential reboot
|
||||
}
|
||||
|
||||
if (!pending && current_rtc == SafeModeComponent::ENTER_SAFE_MODE_MAGIC) {
|
||||
@@ -104,7 +103,6 @@ bool SafeModeComponent::should_enter_safe_mode(uint8_t num_attempts, uint32_t en
|
||||
if (rtc_val < num_attempts && !is_manual) {
|
||||
// increment counter
|
||||
this->write_rtc_(rtc_val + 1);
|
||||
global_preferences->sync(); // Must persist before potential crash
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -131,7 +129,10 @@ bool SafeModeComponent::should_enter_safe_mode(uint8_t num_attempts, uint32_t en
|
||||
return true;
|
||||
}
|
||||
|
||||
void SafeModeComponent::write_rtc_(uint32_t val) { this->rtc_.save(&val); }
|
||||
void SafeModeComponent::write_rtc_(uint32_t val) {
|
||||
this->rtc_.save(&val);
|
||||
global_preferences->sync();
|
||||
}
|
||||
|
||||
uint32_t SafeModeComponent::read_rtc_() {
|
||||
uint32_t val;
|
||||
@@ -140,7 +141,12 @@ uint32_t SafeModeComponent::read_rtc_() {
|
||||
return val;
|
||||
}
|
||||
|
||||
void SafeModeComponent::clean_rtc() { this->write_rtc_(0); }
|
||||
void SafeModeComponent::clean_rtc() {
|
||||
// Save without sync - preferences will be written at shutdown or by IntervalSyncer
|
||||
// This avoids blocking the loop for 50+ ms on flash write
|
||||
uint32_t val = 0;
|
||||
this->rtc_.save(&val);
|
||||
}
|
||||
|
||||
void SafeModeComponent::on_safe_shutdown() {
|
||||
if (this->read_rtc_() != SafeModeComponent::ENTER_SAFE_MODE_MAGIC)
|
||||
|
||||
Reference in New Issue
Block a user