From bd9029c2b2aad3634ed9f3cba41729534293fb97 Mon Sep 17 00:00:00 2001 From: brisk Date: Sat, 27 Jul 2024 14:39:33 +0930 Subject: [PATCH] pulse_counter_ulp: avoid zero --- .../components/pulse_counter_ulp/pulse_counter_ulp_sensor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.cpp b/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.cpp index 1919a5d0ce..f259b6022f 100644 --- a/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.cpp +++ b/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.cpp @@ -136,8 +136,8 @@ void PulseCounterUlpSensor::dump_config() { void PulseCounterUlpSensor::update() { UlpProgram::state raw = this->storage_.pop_state(); clock::time_point now = clock::now(); - auto interval = now - this->last_time_; - if (this->last_time_ != clock::time_point{}) { + clock::duration interval = now - this->last_time_; + if (interval != clock::duration::zero()) { float value = std::chrono::minutes{1} * static_cast(raw.edge_count) / interval; // pulses per minute ESP_LOGD(TAG, "'%s': Retrieved counter: %0.2f pulses/min", this->get_name().c_str(), value); this->publish_state(value);