Browse Source

Fixed rounding error issue in slider sensor.

Thanks Jos!
pull/31/head
Maurice Makaay 3 years ago
parent
commit
7122f1e551
1 changed files with 7 additions and 0 deletions
  1. +7
    -0
      components/xiaomi_bslamp2/sensor/slider_sensor.h

+ 7
- 0
components/xiaomi_bslamp2/sensor/slider_sensor.h View File

@ -40,6 +40,13 @@ class XiaomiBslamp2SliderSensor : public sensor::Sensor, public Component {
float corrected_level = max(0.0f, level - 2.0f); float corrected_level = max(0.0f, level - 2.0f);
float final_level = range_from_ + (slope_ * corrected_level); float final_level = range_from_ + (slope_ * corrected_level);
// Accomodate for rounding errors that might push the result
// value just past the "range to" value.
if (final_level > range_to_) {
final_level = range_to_;
}
this->publish_state(final_level); this->publish_state(final_level);
} }
}); });


Loading…
Cancel
Save