mirror of
https://github.com/esphome/esphome.git
synced 2025-09-27 15:42:22 +01:00
Add initial_run to regular lambda light effect (#3059)
This commit is contained in:
@@ -102,21 +102,24 @@ class RandomLightEffect : public LightEffect {
|
||||
|
||||
class LambdaLightEffect : public LightEffect {
|
||||
public:
|
||||
LambdaLightEffect(const std::string &name, std::function<void()> f, uint32_t update_interval)
|
||||
LambdaLightEffect(const std::string &name, std::function<void(bool initial_run)> f, uint32_t update_interval)
|
||||
: LightEffect(name), f_(std::move(f)), update_interval_(update_interval) {}
|
||||
|
||||
void start() override { this->initial_run_ = true; }
|
||||
void apply() override {
|
||||
const uint32_t now = millis();
|
||||
if (now - this->last_run_ >= this->update_interval_) {
|
||||
this->last_run_ = now;
|
||||
this->f_();
|
||||
this->f_(this->initial_run_);
|
||||
this->initial_run_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
std::function<void()> f_;
|
||||
std::function<void(bool initial_run)> f_;
|
||||
uint32_t update_interval_;
|
||||
uint32_t last_run_{0};
|
||||
bool initial_run_;
|
||||
};
|
||||
|
||||
class AutomationLightEffect : public LightEffect {
|
||||
|
Reference in New Issue
Block a user