mirror of
https://github.com/esphome/esphome.git
synced 2024-12-25 06:54:52 +01:00
pulse_counter_ulp: avoid zero
This commit is contained in:
parent
c882b58e53
commit
bd9029c2b2
1 changed files with 2 additions and 2 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue