[pzemdc] Use register_apply_action for pzemdc.reset_energy (#19651)

This commit is contained in:
J. Nick Koston
2026-09-25 14:31:11 -04:00
committed by GitHub
parent 9ae83f2830
commit 9c2616ef7e
2 changed files with 2 additions and 17 deletions
-11
View File
@@ -1,6 +1,5 @@
#pragma once
#include "esphome/core/automation.h"
#include "esphome/core/component.h"
#include "esphome/components/sensor/sensor.h"
#include "esphome/components/modbus/modbus.h"
@@ -34,14 +33,4 @@ class PZEMDC final : public PollingComponent, public modbus::ModbusClientDevice
sensor::Sensor *energy_sensor_{nullptr};
};
template<typename... Ts> class ResetEnergyAction final : public Action<Ts...> {
public:
ResetEnergyAction(PZEMDC *pzemdc) : pzemdc_(pzemdc) {}
void play(const Ts &...x) override { this->pzemdc_->reset_energy(); }
protected:
PZEMDC *pzemdc_;
};
} // namespace esphome::pzemdc
+2 -6
View File
@@ -27,9 +27,6 @@ AUTO_LOAD = ["modbus"]
pzemdc_ns = cg.esphome_ns.namespace("pzemdc")
PZEMDC = pzemdc_ns.class_("PZEMDC", cg.PollingComponent, modbus.ModbusClientDevice)
# Actions
ResetEnergyAction = pzemdc_ns.class_("ResetEnergyAction", automation.Action)
CONFIG_SCHEMA = (
cv.Schema(
{
@@ -65,15 +62,14 @@ CONFIG_SCHEMA = (
)
automation.register_simple_action(
automation.register_apply_action(
"pzemdc.reset_energy",
ResetEnergyAction,
maybe_simple_id(
{
cv.GenerateID(CONF_ID): cv.use_id(PZEMDC),
}
),
synchronous=True,
automation.ApplyCall("reset_energy()"),
)