[sensor] Fix bug in percentage based delta filter (#8157)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Jonathan Swoboda 2025-07-31 22:15:56 -04:00 committed by GitHub
parent f13e742bd5
commit 0954a6185c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -375,13 +375,11 @@ optional<float> DeltaFilter::new_value(float value) {
if (std::isnan(this->last_value_)) {
return {};
} else {
if (this->percentage_mode_) {
this->current_delta_ = fabsf(value * this->delta_);
}
return this->last_value_ = value;
}
}
if (std::isnan(this->last_value_) || fabsf(value - this->last_value_) >= this->current_delta_) {
float diff = fabsf(value - this->last_value_);
if (std::isnan(this->last_value_) || (diff > 0.0f && diff >= this->current_delta_)) {
if (this->percentage_mode_) {
this->current_delta_ = fabsf(value * this->delta_);
}