pulse_counter_ulp: remove time component

This commit is contained in:
brisk 2024-07-21 21:57:46 +09:30
parent 7cd5bad1c2
commit 31e72a5232
3 changed files with 0 additions and 45 deletions

View file

@ -105,14 +105,6 @@ void PulseCounterUlpSensor::setup() {
this->mark_failed();
return;
}
#ifdef CONF_USE_TIME
this->time_id_->add_on_time_sync_callback([this]() {
this->time_is_synchronized_ = true;
this->update();
});
this->pref_ = global_preferences->make_preference<timestamp_t>(this->get_object_id_hash());
this->pref_.load(&this->last_time_);
#endif
}
void PulseCounterUlpSensor::set_total_pulses(uint32_t pulses) {
@ -129,23 +121,10 @@ void PulseCounterUlpSensor::dump_config() {
}
void PulseCounterUlpSensor::update() {
#ifdef CONF_USE_TIME
// Can't clear the pulse count until we can report the rate, so there's
// nothing to do until the time is synchronized
if (!time_is_synchronized_) {
return;
}
#endif
pulse_counter_t raw = this->storage_.read_raw_value();
timestamp_t now;
timestamp_t interval;
#ifdef CONF_USE_TIME
// Convert to ms to match units when not using a Time component.
now = this->time_id_->timestamp_now() * 1000;
#else
now = millis();
#endif
interval = now - this->last_time_;
if (this->last_time_ != 0) {
float value = (60000.0f * raw) / float(interval); // per minute
@ -159,9 +138,6 @@ void PulseCounterUlpSensor::update() {
this->total_sensor_->publish_state(current_total_);
}
this->last_time_ = now;
#ifdef CONF_USE_TIME
this->pref_.save(&this->last_time_);
#endif
}
} // namespace pulse_counter_ulp

View file

@ -4,10 +4,6 @@
#include "esphome/core/hal.h"
#include "esphome/components/sensor/sensor.h"
#ifdef USE_TIME
#include "esphome/components/time/real_time_clock.h"
#endif
#include <cinttypes>
namespace esphome {
@ -36,9 +32,6 @@ class PulseCounterUlpSensor : public sensor::Sensor, public PollingComponent {
void set_rising_edge_mode(CountMode mode) { storage_.rising_edge_mode = mode; }
void set_falling_edge_mode(CountMode mode) { storage_.falling_edge_mode = mode; }
void set_total_sensor(sensor::Sensor *total_sensor) { total_sensor_ = total_sensor; }
#ifdef USE_TIME
void set_time_id(time::RealTimeClock *time_id) { time_id_ = time_id; }
#endif
void set_total_pulses(uint32_t pulses);
@ -54,12 +47,6 @@ class PulseCounterUlpSensor : public sensor::Sensor, public PollingComponent {
timestamp_t last_time_{0};
uint32_t current_total_{0};
sensor::Sensor *total_sensor_{nullptr};
#ifdef USE_TIME
time::RealTimeClock *time_id_{nullptr};
bool time_is_synchronized_{false};
// Store last_time_ across deep sleep
ESPPreferenceObject pref_{};
#endif
};
} // namespace pulse_counter_ulp

View file

@ -4,7 +4,6 @@ import esphome.config_validation as cv
from esphome import automation, pins
from esphome.components import sensor
from esphome.components import esp32
from esphome.components import time
from esphome.const import (
CONF_COUNT_MODE,
CONF_FALLING_EDGE,
@ -12,7 +11,6 @@ from esphome.const import (
CONF_PIN,
CONF_RISING_EDGE,
CONF_NUMBER,
CONF_TIME_ID,
CONF_TOTAL,
CONF_VALUE,
ICON_PULSE,
@ -94,7 +92,6 @@ CONFIG_SCHEMA = cv.All(
accuracy_decimals=0,
state_class=STATE_CLASS_TOTAL_INCREASING,
),
cv.Optional(CONF_TIME_ID): cv.use_id(time.RealTimeClock),
},
)
.extend(cv.polling_component_schema("60s")),
@ -123,11 +120,6 @@ async def to_code(config):
cg.add(var.set_rising_edge_mode(count[CONF_RISING_EDGE]))
cg.add(var.set_falling_edge_mode(count[CONF_FALLING_EDGE]))
if CONF_TIME_ID in config:
cg.add_define("CONF_USE_TIME", True)
time_ = await cg.get_variable(config[CONF_TIME_ID])
cg.add(var.set_time_id(time_))
if CONF_TOTAL in config:
sens = await sensor.new_sensor(config[CONF_TOTAL])
cg.add(var.set_total_sensor(sens))