From c882b58e53e794bb6adac7c5072cd7d8cefa2d07 Mon Sep 17 00:00:00 2001 From: brisk Date: Wed, 24 Jul 2024 14:07:02 +0930 Subject: [PATCH] pulse_counter_ulp: Don't break chrono type-safety --- .../pulse_counter_ulp/pulse_counter_ulp_sensor.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 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 c21f66b0f8..1919a5d0ce 100644 --- a/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.cpp +++ b/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.cpp @@ -135,12 +135,10 @@ void PulseCounterUlpSensor::dump_config() { void PulseCounterUlpSensor::update() { UlpProgram::state raw = this->storage_.pop_state(); - clock::time_point now; - std::chrono::duration> minutes; - now = clock::now(); - minutes = now - this->last_time_; + clock::time_point now = clock::now(); + auto interval = now - this->last_time_; if (this->last_time_ != clock::time_point{}) { - float value = raw.edge_count / minutes.count(); // pulses per minute + 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); }