mirror of
https://github.com/esphome/esphome.git
synced 2024-12-02 11:44:13 +01:00
491f8cc611
Co-authored-by: Alex <33379584+alexyao2015@users.noreply.github.com> Co-authored-by: Otto winter <otto@otto-winter.com>
23 lines
612 B
C++
23 lines
612 B
C++
#pragma once
|
|
|
|
#include "esphome/core/preferences.h"
|
|
#include "esphome/core/component.h"
|
|
|
|
namespace esphome {
|
|
namespace preferences {
|
|
|
|
class IntervalSyncer : public Component {
|
|
public:
|
|
void set_write_interval(uint32_t write_interval) { write_interval_ = write_interval; }
|
|
void setup() override {
|
|
set_interval(write_interval_, []() { global_preferences->sync(); });
|
|
}
|
|
void on_shutdown() override { global_preferences->sync(); }
|
|
float get_setup_priority() const override { return setup_priority::BUS; }
|
|
|
|
protected:
|
|
uint32_t write_interval_;
|
|
};
|
|
|
|
} // namespace preferences
|
|
} // namespace esphome
|