ESPHome 2025.9.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 : public Component {
10 public:
11 void set_write_interval(uint32_t write_interval) { this->write_interval_ = write_interval; }
12 void setup() override {
13 if (this->write_interval_ != 0) {
15 // When using interval-based syncing, we don't need the loop
16 this->disable_loop();
17 }
18 }
19 void loop() override {
20 if (this->write_interval_ == 0) {
22 }
23 }
24 void on_shutdown() override { global_preferences->sync(); }
25 float get_setup_priority() const override { return setup_priority::BUS; }
26
27 protected:
28 uint32_t write_interval_{60000};
29};
30
31} // namespace preferences
32} // namespace esphome
void set_interval(const std::string &name, uint32_t interval, std::function< void()> &&f)
Set an interval function with a unique name.
Definition component.cpp:89
void disable_loop()
Disable this component's loop.
virtual bool sync()=0
Commit pending writes to flash.
void set_write_interval(uint32_t write_interval)
Definition syncer.h:11
float get_setup_priority() const override
Definition syncer.h:25
const float BUS
For communication buses like i2c/spi.
Definition component.cpp:47
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
ESPPreferences * global_preferences