Fix light state remaining on after turn off with transition (#2509)

This commit is contained in:
Oxan van Leeuwen 2021-10-13 21:53:00 +02:00 committed by Jesse Hills
parent e63c7b483b
commit b3b9ccd314
No known key found for this signature in database
GPG key ID: BEAAE804EFD8E83A

View file

@ -18,10 +18,13 @@ class LightTransitionTransformer : public LightTransformer {
this->start_values_.set_brightness(0.0f); this->start_values_.set_brightness(0.0f);
} }
// When turning light off from on state, use source state and only decrease brightness to zero. // When turning light off from on state, use source state and only decrease brightness to zero. Use a second
// variable for transition end state, as overwriting target_values breaks LightState logic.
if (this->start_values_.is_on() && !this->target_values_.is_on()) { if (this->start_values_.is_on() && !this->target_values_.is_on()) {
this->target_values_ = LightColorValues(this->start_values_); this->end_values_ = LightColorValues(this->start_values_);
this->target_values_.set_brightness(0.0f); this->end_values_.set_brightness(0.0f);
} else {
this->end_values_ = LightColorValues(this->target_values_);
} }
// When changing color mode, go through off state, as color modes are orthogonal and there can't be two active. // When changing color mode, go through off state, as color modes are orthogonal and there can't be two active.
@ -43,7 +46,7 @@ class LightTransitionTransformer : public LightTransformer {
} }
LightColorValues &start = this->changing_color_mode_ && p > 0.5f ? this->intermediate_values_ : this->start_values_; LightColorValues &start = this->changing_color_mode_ && p > 0.5f ? this->intermediate_values_ : this->start_values_;
LightColorValues &end = this->changing_color_mode_ && p < 0.5f ? this->intermediate_values_ : this->target_values_; LightColorValues &end = this->changing_color_mode_ && p < 0.5f ? this->intermediate_values_ : this->end_values_;
if (this->changing_color_mode_) if (this->changing_color_mode_)
p = p < 0.5f ? p * 2 : (p - 0.5) * 2; p = p < 0.5f ? p * 2 : (p - 0.5) * 2;
@ -57,6 +60,7 @@ class LightTransitionTransformer : public LightTransformer {
static float smoothed_progress(float x) { return x * x * x * (x * (x * 6.0f - 15.0f) + 10.0f); } static float smoothed_progress(float x) { return x * x * x * (x * (x * 6.0f - 15.0f) + 10.0f); }
bool changing_color_mode_{false}; bool changing_color_mode_{false};
LightColorValues end_values_{};
LightColorValues intermediate_values_{}; LightColorValues intermediate_values_{};
}; };