esphome/esphome/components/preferences/syncer.h
Alex 491f8cc611
Configurable Flash Write Interval (#2119)
Co-authored-by: Alex <33379584+alexyao2015@users.noreply.github.com>
Co-authored-by: Otto winter <otto@otto-winter.com>
2021-09-21 13:47:51 +02:00

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