mirror of
https://github.com/esphome/esphome.git
synced 2026-09-29 07:50:21 +00:00
[pzemdc] Use register_apply_action for pzemdc.reset_energy (#19651)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()"),
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user