mirror of
https://github.com/esphome/esphome.git
synced 2024-11-27 09:18:00 +01:00
pulse_counter_ulp: Don't break chrono type-safety
This commit is contained in:
parent
b41746cc54
commit
c882b58e53
1 changed files with 3 additions and 5 deletions
|
@ -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<float, std::ratio<60>> 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<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