Add startup_delay to interval. (#5327)

This commit is contained in:
Clyde Stubbs
2023-11-23 18:31:23 +11:00
committed by GitHub
parent 8738cef5a3
commit 3ac59180ab
3 changed files with 25 additions and 2 deletions
+19 -1
View File
@@ -8,8 +8,26 @@ namespace interval {
class IntervalTrigger : public Trigger<>, public PollingComponent {
public:
void update() override { this->trigger(); }
void update() override {
if (this->started_)
this->trigger();
}
void setup() override {
if (this->startup_delay_ == 0) {
this->started_ = true;
} else {
this->set_timeout(this->startup_delay_, [this] { this->started_ = true; });
}
}
void set_startup_delay(const uint32_t startup_delay) { this->startup_delay_ = startup_delay; }
float get_setup_priority() const override { return setup_priority::DATA; }
protected:
uint32_t startup_delay_{0};
bool started_{false};
};
} // namespace interval