ESPHome 2026.5.0-dev
Loading...
Searching...
No Matches
syncer.h
Go to the documentation of this file.
1#pragma once
2
5
6namespace esphome {
7namespace preferences {
8
9class IntervalSyncer final : public Component {
10 public:
11#ifdef USE_PREFERENCES_SYNC_EVERY_LOOP
12 void loop() override { global_preferences->sync(); }
13#else
14 void set_write_interval(uint32_t write_interval) { this->write_interval_ = write_interval; }
15 void setup() override {
16 this->set_interval(this->write_interval_, []() { global_preferences->sync(); });
17 }
18#endif
19 void on_shutdown() override { global_preferences->sync(); }
20 float get_setup_priority() const override { return setup_priority::BUS; }
21
22#ifndef USE_PREFERENCES_SYNC_EVERY_LOOP
23 protected:
25#endif
26};
27
28} // namespace preferences
29} // namespace esphome
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:14
float get_setup_priority() const override
Definition syncer.h:20
constexpr float BUS
For communication buses like i2c/spi.
Definition component.h:36
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
ESPPreferences * global_preferences
static void uint32_t
bool sync()
Commit pending writes to flash.
Definition preferences.h:32