mirror of
https://github.com/esphome/esphome.git
synced 2026-09-28 15:30:21 +00:00
[bl0906] Use register_apply_action for bl0906.reset_energy (#19688)
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
#include "esphome/components/uart/uart.h"
|
||||
#include "esphome/core/automation.h"
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/datatypes.h"
|
||||
|
||||
@@ -47,8 +46,6 @@ struct sbe24_t { // NOLINT(readability-identifier-naming,altera-struct-pack-ali
|
||||
int8_t h{0};
|
||||
} __attribute__((packed));
|
||||
|
||||
template<typename... Ts> class ResetEnergyAction;
|
||||
|
||||
class BL0906;
|
||||
|
||||
using ActionCallbackFuncPtr = void (BL0906::*)();
|
||||
@@ -85,9 +82,10 @@ class BL0906 final : public PollingComponent, public uart::UARTDevice {
|
||||
void setup() override;
|
||||
void dump_config() override;
|
||||
|
||||
protected:
|
||||
template<typename... Ts> friend class ResetEnergyAction;
|
||||
/// Queue an energy counter reset for the next poll
|
||||
void reset_energy() { this->enqueue_action_(&BL0906::reset_energy_); }
|
||||
|
||||
protected:
|
||||
void reset_energy_();
|
||||
|
||||
void read_data_(uint8_t address, float reference, sensor::Sensor *sensor);
|
||||
@@ -103,9 +101,4 @@ class BL0906 final : public PollingComponent, public uart::UARTDevice {
|
||||
std::vector<ActionCallbackFuncPtr> action_queue_{};
|
||||
};
|
||||
|
||||
template<typename... Ts> class ResetEnergyAction final : public Action<Ts...>, public Parented<BL0906> {
|
||||
public:
|
||||
void play(const Ts &...x) override { this->parent_->enqueue_action_(&BL0906::reset_energy_); }
|
||||
};
|
||||
|
||||
} // namespace esphome::bl0906
|
||||
|
||||
@@ -43,7 +43,6 @@ CONF_TOTAL_ENERGY = "total_energy"
|
||||
|
||||
bl0906_ns = cg.esphome_ns.namespace("bl0906")
|
||||
BL0906 = bl0906_ns.class_("BL0906", cg.PollingComponent, uart.UARTDevice)
|
||||
ResetEnergyAction = bl0906_ns.class_("ResetEnergyAction", automation.Action)
|
||||
|
||||
CONFIG_SCHEMA = (
|
||||
cv.Schema(
|
||||
@@ -136,15 +135,14 @@ FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema(
|
||||
)
|
||||
|
||||
|
||||
automation.register_parented_action(
|
||||
automation.register_apply_action(
|
||||
"bl0906.reset_energy",
|
||||
ResetEnergyAction,
|
||||
maybe_simple_id(
|
||||
{
|
||||
cv.Required(CONF_ID): cv.use_id(BL0906),
|
||||
}
|
||||
),
|
||||
synchronous=True,
|
||||
automation.ApplyCall("reset_energy()"),
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user