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