mirror of
https://github.com/esphome/esphome.git
synced 2026-09-29 07:50:21 +00:00
[ufire_ec] Use register_apply_action for calibrate_probe and reset (#19675)
This commit is contained in:
@@ -14,8 +14,6 @@ from esphome.const import (
|
||||
UNIT_CELSIUS,
|
||||
UNIT_MILLISIEMENS_PER_CENTIMETER,
|
||||
)
|
||||
from esphome.core import ID
|
||||
from esphome.cpp_generator import MockObj, TemplateArgsType
|
||||
from esphome.types import ConfigType
|
||||
|
||||
DEPENDENCIES = ["i2c"]
|
||||
@@ -29,12 +27,6 @@ UFireECComponent = ufire_ec_ns.class_(
|
||||
"UFireECComponent", cg.PollingComponent, i2c.I2CDevice
|
||||
)
|
||||
|
||||
# Actions
|
||||
UFireECCalibrateProbeAction = ufire_ec_ns.class_(
|
||||
"UFireECCalibrateProbeAction", automation.Action
|
||||
)
|
||||
UFireECResetAction = ufire_ec_ns.class_("UFireECResetAction", automation.Action)
|
||||
|
||||
CONFIG_SCHEMA = (
|
||||
cv.Schema(
|
||||
{
|
||||
@@ -96,25 +88,14 @@ UFIRE_EC_CALIBRATE_PROBE_SCHEMA = cv.Schema(
|
||||
)
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
automation.register_apply_action(
|
||||
"ufire_ec.calibrate_probe",
|
||||
UFireECCalibrateProbeAction,
|
||||
UFIRE_EC_CALIBRATE_PROBE_SCHEMA,
|
||||
synchronous=True,
|
||||
automation.ApplyCall(
|
||||
"calibrate_probe({}, {})",
|
||||
((CONF_SOLUTION, cg.float_), (CONF_TEMPERATURE, cg.float_)),
|
||||
),
|
||||
)
|
||||
async def ufire_ec_calibrate_probe_to_code(
|
||||
config: ConfigType,
|
||||
action_id: ID,
|
||||
template_arg: cg.TemplateArguments,
|
||||
args: TemplateArgsType,
|
||||
) -> MockObj:
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(action_id, template_arg, paren)
|
||||
solution_ = await cg.templatable(config[CONF_SOLUTION], args, cg.float_)
|
||||
temperature_ = await cg.templatable(config[CONF_TEMPERATURE], args, cg.float_)
|
||||
cg.add(var.set_solution(solution_))
|
||||
cg.add(var.set_temperature(temperature_))
|
||||
return var
|
||||
|
||||
|
||||
UFIRE_EC_RESET_SCHEMA = cv.Schema(
|
||||
@@ -124,9 +105,6 @@ UFIRE_EC_RESET_SCHEMA = cv.Schema(
|
||||
)
|
||||
|
||||
|
||||
automation.register_simple_action(
|
||||
"ufire_ec.reset",
|
||||
UFireECResetAction,
|
||||
UFIRE_EC_RESET_SCHEMA,
|
||||
synchronous=True,
|
||||
automation.register_apply_action(
|
||||
"ufire_ec.reset", UFIRE_EC_RESET_SCHEMA, automation.ApplyCall("reset_board()")
|
||||
)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/automation.h"
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
@@ -58,28 +57,4 @@ class UFireECComponent final : public PollingComponent, public i2c::I2CDevice {
|
||||
float temperature_coefficient_{0.0};
|
||||
};
|
||||
|
||||
template<typename... Ts> class UFireECCalibrateProbeAction final : public Action<Ts...> {
|
||||
public:
|
||||
UFireECCalibrateProbeAction(UFireECComponent *parent) : parent_(parent) {}
|
||||
TEMPLATABLE_VALUE(float, solution)
|
||||
TEMPLATABLE_VALUE(float, temperature)
|
||||
|
||||
void play(const Ts &...x) override {
|
||||
this->parent_->calibrate_probe(this->solution_.value(x...), this->temperature_.value(x...));
|
||||
}
|
||||
|
||||
protected:
|
||||
UFireECComponent *parent_;
|
||||
};
|
||||
|
||||
template<typename... Ts> class UFireECResetAction final : public Action<Ts...> {
|
||||
public:
|
||||
UFireECResetAction(UFireECComponent *parent) : parent_(parent) {}
|
||||
|
||||
void play(const Ts &...x) override { this->parent_->reset_board(); }
|
||||
|
||||
protected:
|
||||
UFireECComponent *parent_;
|
||||
};
|
||||
|
||||
} // namespace esphome::ufire_ec
|
||||
|
||||
Reference in New Issue
Block a user