mirror of
https://github.com/esphome/esphome.git
synced 2026-02-28 01:44:20 -07:00
[light] Fix millis overflow in transition progress and flash timing (#14292)
Co-authored-by: J. Nick Koston <nick@koston.org> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -44,12 +44,11 @@ class LightTransformer {
|
||||
/// The progress of this transition, on a scale of 0 to 1.
|
||||
float get_progress_() {
|
||||
uint32_t now = esphome::millis();
|
||||
if (now < this->start_time_)
|
||||
return 0.0f;
|
||||
if (now >= this->start_time_ + this->length_)
|
||||
uint32_t elapsed = now - this->start_time_;
|
||||
if (elapsed >= this->length_)
|
||||
return 1.0f;
|
||||
|
||||
return clamp((now - this->start_time_) / float(this->length_), 0.0f, 1.0f);
|
||||
return clamp(elapsed / float(this->length_), 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
uint32_t start_time_;
|
||||
|
||||
@@ -78,7 +78,7 @@ class LightFlashTransformer : public LightTransformer {
|
||||
optional<LightColorValues> apply() override {
|
||||
optional<LightColorValues> result = {};
|
||||
|
||||
if (this->transformer_ == nullptr && millis() > this->start_time_ + this->length_ - this->transition_length_) {
|
||||
if (this->transformer_ == nullptr && millis() - this->start_time_ > this->length_ - this->transition_length_) {
|
||||
// second transition back to start value
|
||||
this->transformer_ = this->state_.get_output()->create_default_transition();
|
||||
this->transformer_->setup(this->state_.current_values, this->get_start_values(), this->transition_length_);
|
||||
|
||||
Reference in New Issue
Block a user