1
0
mirror of https://github.com/esphome/esphome.git synced 2026-02-08 08:41:59 +00:00

[safe_mode] Defer preference sync in clean_rtc to avoid blocking event loop (#12625)

This commit is contained in:
J. Nick Koston
2025-12-22 11:13:51 -10:00
committed by GitHub
parent 918bc4b74f
commit c8b531ac06

View File

@@ -141,7 +141,14 @@ 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. If the device crashes
// before sync, the boot wasn't really successful anyway and the counter should
// remain incremented.
uint32_t val = 0;
this->rtc_.save(&val);
}
void SafeModeComponent::on_safe_shutdown() {
if (this->read_rtc_() != SafeModeComponent::ENTER_SAFE_MODE_MAGIC)