From c8ccb06f11e28c035f2d340444cfb3b3e49110ff Mon Sep 17 00:00:00 2001 From: Andrew Zaborowski Date: Tue, 17 Dec 2019 12:08:37 +0100 Subject: [PATCH] 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. --- esphome/components/ct_clamp/ct_clamp_sensor.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/esphome/components/ct_clamp/ct_clamp_sensor.cpp b/esphome/components/ct_clamp/ct_clamp_sensor.cpp index 674cc0ae98..c1e3bec486 100644 --- a/esphome/components/ct_clamp/ct_clamp_sensor.cpp +++ b/esphome/components/ct_clamp/ct_clamp_sensor.cpp @@ -64,6 +64,8 @@ void CTClampSensor::loop() { // Perform a single sample float value = this->source_->sample(); + if (isnan(value)) + return; if (this->is_calibrating_offset_) { this->sample_sum_ += value;