ESPHome  2024.11.2
pzemdc.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 #include <vector>
9 
10 namespace esphome {
11 namespace pzemdc {
12 
14  public:
15  void set_voltage_sensor(sensor::Sensor *voltage_sensor) { voltage_sensor_ = voltage_sensor; }
16  void set_current_sensor(sensor::Sensor *current_sensor) { current_sensor_ = current_sensor; }
17  void set_power_sensor(sensor::Sensor *power_sensor) { power_sensor_ = power_sensor; }
18  void set_energy_sensor(sensor::Sensor *energy_sensor) { energy_sensor_ = energy_sensor; }
19 
20  void update() override;
21 
22  void on_modbus_data(const std::vector<uint8_t> &data) override;
23 
24  void dump_config() override;
25 
26  void reset_energy();
27 
28  protected:
33 };
34 
35 template<typename... Ts> class ResetEnergyAction : public Action<Ts...> {
36  public:
37  ResetEnergyAction(PZEMDC *pzemdc) : pzemdc_(pzemdc) {}
38 
39  void play(Ts... x) override { this->pzemdc_->reset_energy(); }
40 
41  protected:
43 };
44 
45 } // namespace pzemdc
46 } // namespace esphome
void dump_config() override
Definition: pzemdc.cpp:56
sensor::Sensor * power_sensor_
Definition: pzemdc.h:31
void set_power_sensor(sensor::Sensor *power_sensor)
Definition: pzemdc.h:17
ResetEnergyAction(PZEMDC *pzemdc)
Definition: pzemdc.h:37
uint16_t x
Definition: tt21100.cpp:17
void set_voltage_sensor(sensor::Sensor *voltage_sensor)
Definition: pzemdc.h:15
void set_current_sensor(sensor::Sensor *current_sensor)
Definition: pzemdc.h:16
void play(Ts... x) override
Definition: pzemdc.h:39
sensor::Sensor * current_sensor_
Definition: pzemdc.h:30
This class simplifies creating components that periodically check a state.
Definition: component.h:283
void set_energy_sensor(sensor::Sensor *energy_sensor)
Definition: pzemdc.h:18
sensor::Sensor * energy_sensor_
Definition: pzemdc.h:32
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void on_modbus_data(const std::vector< uint8_t > &data) override
Definition: pzemdc.cpp:13
Base-class for all sensors.
Definition: sensor.h:57
sensor::Sensor * voltage_sensor_
Definition: pzemdc.h:29
void update() override
Definition: pzemdc.cpp:55