mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 16:38:16 +01:00
This commit is contained in:
parent
a4867a00ea
commit
aad03f1bf5
2 changed files with 10 additions and 0 deletions
|
@ -6,6 +6,14 @@ namespace pzem004t {
|
|||
|
||||
static const char *const TAG = "pzem004t";
|
||||
|
||||
void PZEM004T::setup() {
|
||||
// Clear UART buffer
|
||||
while (this->available())
|
||||
this->read();
|
||||
// Set module address
|
||||
this->write_state_(SET_ADDRESS);
|
||||
}
|
||||
|
||||
void PZEM004T::loop() {
|
||||
const uint32_t now = millis();
|
||||
if (now - this->last_read_ > 500 && this->available() < 7) {
|
||||
|
|
|
@ -14,6 +14,8 @@ class PZEM004T : public PollingComponent, public uart::UARTDevice {
|
|||
void set_power_sensor(sensor::Sensor *power_sensor) { power_sensor_ = power_sensor; }
|
||||
void set_energy_sensor(sensor::Sensor *energy_sensor) { energy_sensor_ = energy_sensor; }
|
||||
|
||||
void setup() override;
|
||||
|
||||
void loop() override;
|
||||
|
||||
void update() override;
|
||||
|
|
Loading…
Reference in a new issue