ESPHome 2026.5.0
Loading...
Searching...
No Matches
syncer.h
Go to the documentation of this file.
1#pragma once
2
5
7
8class IntervalSyncer final : public Component {
9 public:
10#ifdef USE_PREFERENCES_SYNC_EVERY_LOOP
11 void loop() override { global_preferences->sync(); }
12#else
13 void set_write_interval(uint32_t write_interval) { this->write_interval_ = write_interval; }
14 void setup() override {
15 this->set_interval(this->write_interval_, []() { global_preferences->sync(); });
16 }
17#endif
18 void on_shutdown() override { global_preferences->sync(); }
19 float get_setup_priority() const override { return setup_priority::BUS; }
20
21#ifndef USE_PREFERENCES_SYNC_EVERY_LOOP
22 protected:
24#endif
25};
26
27} // namespace esphome::preferences
ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") void set_interval(const std voi set_interval)(const char *name, uint32_t interval, std::function< void()> &&f)
Set an interval function with a unique name.
Definition component.h:417
void set_write_interval(uint32_t write_interval)
Definition syncer.h:13
float get_setup_priority() const override
Definition syncer.h:19
constexpr float BUS
For communication buses like i2c/spi.
Definition component.h:37
ESPPreferences * global_preferences
static void uint32_t
bool sync()
Commit pending writes to flash.
Definition preferences.h:32