pulse_counter_ulp: avoid zero

This commit is contained in:
brisk 2024-07-27 14:39:33 +09:30
parent c882b58e53
commit bd9029c2b2

View file

@ -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<float>(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);