mirror of
https://github.com/esphome/esphome.git
synced 2025-02-21 20:38:16 +00:00
ct_clamp: Check sample() return value is not NaN (#921)
Don't try to update CT clamp's state with NaN values returned from the underlaying sensor. A single IO error in the sensor code will cause a NaN to be returned and if we use that in CTClampSensor's floating point maths both sample_sum_ and offset_ will become NaN and from there every future calculation will use the NaN offset_ and return NaN too.
This commit is contained in:
parent
f5b7cc81d8
commit
c8ccb06f11
@ -64,6 +64,8 @@ void CTClampSensor::loop() {
|
|||||||
|
|
||||||
// Perform a single sample
|
// Perform a single sample
|
||||||
float value = this->source_->sample();
|
float value = this->source_->sample();
|
||||||
|
if (isnan(value))
|
||||||
|
return;
|
||||||
|
|
||||||
if (this->is_calibrating_offset_) {
|
if (this->is_calibrating_offset_) {
|
||||||
this->sample_sum_ += value;
|
this->sample_sum_ += value;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user