Skip to content

Commit

Permalink
Publish the pulse_meter total when setting the total (esphome#5475)
Browse files Browse the repository at this point in the history
  • Loading branch information
TrentHouliston authored Oct 19, 2023
1 parent 9f033bc commit d824719
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ esphome/components/pn532_spi/* @OttoWinter @jesserockz
esphome/components/power_supply/* @esphome/core
esphome/components/preferences/* @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/qmp6988/* @andrewpc
esphome/components/qr_code/* @wjtje
Expand Down
7 changes: 7 additions & 0 deletions esphome/components/pulse_meter/pulse_meter_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ namespace 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() {
this->pin_->setup();
this->isr_pin_ = pin_->to_isr();
Expand Down
3 changes: 2 additions & 1 deletion esphome/components/pulse_meter/pulse_meter_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class PulseMeterSensor : public sensor::Sensor, public Component {
void set_timeout_us(uint32_t timeout) { this->timeout_us_ = timeout; }
void set_total_sensor(sensor::Sensor *sensor) { this->total_sensor_ = sensor; }
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 loop() override;
Expand Down
2 changes: 1 addition & 1 deletion esphome/components/pulse_meter/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
)
from esphome.core import CORE

CODEOWNERS = ["@stevebaxter", "@cstaahl"]
CODEOWNERS = ["@stevebaxter", "@cstaahl", "@TrentHouliston"]

pulse_meter_ns = cg.esphome_ns.namespace("pulse_meter")

Expand Down

0 comments on commit d824719

Please sign in to comment.