Publish the pulse_meter total when setting the total (#5475)

This commit is contained in:
Trent Houliston 2023-10-20 08:28:05 +11:00 committed by GitHub
parent 9f033bce3b
commit d82471942f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 3 deletions

View file

@ -225,7 +225,7 @@ esphome/components/pn532_spi/* @OttoWinter @jesserockz
esphome/components/power_supply/* @esphome/core esphome/components/power_supply/* @esphome/core
esphome/components/preferences/* @esphome/core esphome/components/preferences/* @esphome/core
esphome/components/psram/* @esphome/core esphome/components/psram/* @esphome/core
esphome/components/pulse_meter/* @cstaahl @stevebaxter esphome/components/pulse_meter/* @TrentHouliston @cstaahl @stevebaxter
esphome/components/pvvx_mithermometer/* @pasiz esphome/components/pvvx_mithermometer/* @pasiz
esphome/components/qmp6988/* @andrewpc esphome/components/qmp6988/* @andrewpc
esphome/components/qr_code/* @wjtje esphome/components/qr_code/* @wjtje

View file

@ -7,6 +7,13 @@ namespace pulse_meter {
static const char *const TAG = "pulse_meter"; static const char *const TAG = "pulse_meter";
void PulseMeterSensor::set_total_pulses(uint32_t pulses) {
this->total_pulses_ = pulses;
if (this->total_sensor_ != nullptr) {
this->total_sensor_->publish_state(this->total_pulses_);
}
}
void PulseMeterSensor::setup() { void PulseMeterSensor::setup() {
this->pin_->setup(); this->pin_->setup();
this->isr_pin_ = pin_->to_isr(); this->isr_pin_ = pin_->to_isr();

View file

@ -22,7 +22,8 @@ class PulseMeterSensor : public sensor::Sensor, public Component {
void set_timeout_us(uint32_t timeout) { this->timeout_us_ = timeout; } void set_timeout_us(uint32_t timeout) { this->timeout_us_ = timeout; }
void set_total_sensor(sensor::Sensor *sensor) { this->total_sensor_ = sensor; } void set_total_sensor(sensor::Sensor *sensor) { this->total_sensor_ = sensor; }
void set_filter_mode(InternalFilterMode mode) { this->filter_mode_ = mode; } void set_filter_mode(InternalFilterMode mode) { this->filter_mode_ = mode; }
void set_total_pulses(uint32_t pulses) { this->total_pulses_ = pulses; }
void set_total_pulses(uint32_t pulses);
void setup() override; void setup() override;
void loop() override; void loop() override;

View file

@ -19,7 +19,7 @@ from esphome.const import (
) )
from esphome.core import CORE from esphome.core import CORE
CODEOWNERS = ["@stevebaxter", "@cstaahl"] CODEOWNERS = ["@stevebaxter", "@cstaahl", "@TrentHouliston"]
pulse_meter_ns = cg.esphome_ns.namespace("pulse_meter") pulse_meter_ns = cg.esphome_ns.namespace("pulse_meter")