mirror of
https://github.com/esphome/esphome.git
synced 2025-03-13 14:18:14 +00:00
Merge c569668029eec6380edf3b7ce1580acc806068e5 into 755b0bbfc7d404d9ce1a4a02ee8c99c4c838e63f
This commit is contained in:
commit
5571a9273b
@ -193,6 +193,11 @@ class FlickerLightEffect : public LightEffect {
|
||||
explicit FlickerLightEffect(const std::string &name) : LightEffect(name) {}
|
||||
|
||||
void apply() override {
|
||||
const uint32_t now = millis();
|
||||
if (now - this->last_change_ < this->update_interval_) {
|
||||
return;
|
||||
}
|
||||
|
||||
LightColorValues remote = this->state_->remote_values;
|
||||
LightColorValues current = this->state_->current_values;
|
||||
LightColorValues out;
|
||||
@ -217,14 +222,19 @@ class FlickerLightEffect : public LightEffect {
|
||||
call.from_light_color_values(out);
|
||||
call.set_state(true);
|
||||
call.perform();
|
||||
|
||||
this->last_change_ = now;
|
||||
}
|
||||
|
||||
void set_alpha(float alpha) { this->alpha_ = alpha; }
|
||||
void set_intensity(float intensity) { this->intensity_ = intensity; }
|
||||
void set_update_interval(uint32_t update_interval) { this->update_interval_ = update_interval; }
|
||||
|
||||
protected:
|
||||
float intensity_{};
|
||||
float alpha_{};
|
||||
uint32_t last_change_{0};
|
||||
uint32_t update_interval_{};
|
||||
};
|
||||
|
||||
} // namespace light
|
||||
|
@ -327,12 +327,14 @@ async def strobe_effect_to_code(config, effect_id):
|
||||
{
|
||||
cv.Optional(CONF_ALPHA, default=0.95): cv.percentage,
|
||||
cv.Optional(CONF_INTENSITY, default=0.015): cv.percentage,
|
||||
cv.Optional(CONF_UPDATE_INTERVAL, default="0ms"): cv.update_interval,
|
||||
},
|
||||
)
|
||||
async def flicker_effect_to_code(config, effect_id):
|
||||
var = cg.new_Pvariable(effect_id, config[CONF_NAME])
|
||||
cg.add(var.set_alpha(config[CONF_ALPHA]))
|
||||
cg.add(var.set_intensity(config[CONF_INTENSITY]))
|
||||
cg.add(var.set_update_interval(config[CONF_UPDATE_INTERVAL]))
|
||||
return var
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user