[ufire_ise] Use register_apply_action for calibrate_probe_low, calibrate_probe_high and reset (#19670)

This commit is contained in:
J. Nick Koston
2026-09-25 15:41:23 -04:00
committed by GitHub
parent 0ef68c17fd
commit d8696c4f28
4 changed files with 20 additions and 81 deletions
+6 -48
View File
@@ -13,8 +13,6 @@ from esphome.const import (
UNIT_CELSIUS,
UNIT_PH,
)
from esphome.core import ID
from esphome.cpp_generator import MockObj, TemplateArgsType
from esphome.types import ConfigType
DEPENDENCIES = ["i2c"]
@@ -27,15 +25,6 @@ UFireISEComponent = ufire_ise_ns.class_(
"UFireISEComponent", cg.PollingComponent, i2c.I2CDevice
)
# Actions
UFireISECalibrateProbeLowAction = ufire_ise_ns.class_(
"UFireISECalibrateProbeLowAction", automation.Action
)
UFireISECalibrateProbeHighAction = ufire_ise_ns.class_(
"UFireISECalibrateProbeHighAction", automation.Action
)
UFireISEResetAction = ufire_ise_ns.class_("UFireISEResetAction", automation.Action)
CONFIG_SCHEMA = (
cv.Schema(
{
@@ -89,51 +78,20 @@ UFIRE_ISE_CALIBRATE_PROBE_SCHEMA = cv.Schema(
}
)
@automation.register_action(
automation.register_apply_action(
"ufire_ise.calibrate_probe_low",
UFireISECalibrateProbeLowAction,
UFIRE_ISE_CALIBRATE_PROBE_SCHEMA,
synchronous=True,
automation.ApplyField(CONF_SOLUTION, "calibrate_probe_low", cg.float_),
)
async def ufire_ise_calibrate_probe_low_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)
template_ = await cg.templatable(config[CONF_SOLUTION], args, cg.float_)
cg.add(var.set_solution(template_))
return var
@automation.register_action(
automation.register_apply_action(
"ufire_ise.calibrate_probe_high",
UFireISECalibrateProbeHighAction,
UFIRE_ISE_CALIBRATE_PROBE_SCHEMA,
synchronous=True,
automation.ApplyField(CONF_SOLUTION, "calibrate_probe_high", cg.float_),
)
async def ufire_ise_calibrate_probe_high_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)
template_ = await cg.templatable(config[CONF_SOLUTION], args, cg.float_)
cg.add(var.set_solution(template_))
return var
UFIRE_ISE_RESET_SCHEMA = cv.Schema({cv.GenerateID(): cv.use_id(UFireISEComponent)})
automation.register_simple_action(
"ufire_ise.reset",
UFireISEResetAction,
UFIRE_ISE_RESET_SCHEMA,
synchronous=True,
automation.register_apply_action(
"ufire_ise.reset", UFIRE_ISE_RESET_SCHEMA, automation.ApplyCall("reset_board()")
)
-33
View File
@@ -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,36 +57,4 @@ class UFireISEComponent final : public PollingComponent, public i2c::I2CDevice {
sensor::Sensor *ph_sensor_{nullptr};
};
template<typename... Ts> class UFireISECalibrateProbeLowAction final : public Action<Ts...> {
public:
UFireISECalibrateProbeLowAction(UFireISEComponent *parent) : parent_(parent) {}
TEMPLATABLE_VALUE(float, solution)
void play(const Ts &...x) override { this->parent_->calibrate_probe_low(this->solution_.value(x...)); }
protected:
UFireISEComponent *parent_;
};
template<typename... Ts> class UFireISECalibrateProbeHighAction final : public Action<Ts...> {
public:
UFireISECalibrateProbeHighAction(UFireISEComponent *parent) : parent_(parent) {}
TEMPLATABLE_VALUE(float, solution)
void play(const Ts &...x) override { this->parent_->calibrate_probe_high(this->solution_.value(x...)); }
protected:
UFireISEComponent *parent_;
};
template<typename... Ts> class UFireISEResetAction final : public Action<Ts...> {
public:
UFireISEResetAction(UFireISEComponent *parent) : parent_(parent) {}
void play(const Ts &...x) override { this->parent_->reset_board(); }
protected:
UFireISEComponent *parent_;
};
} // namespace esphome::ufire_ise
@@ -0,0 +1,10 @@
button:
- platform: template
name: uFire ISE Actions
on_press:
- ufire_ise.calibrate_probe_high:
id: ufire_ise_sensor
solution: !lambda return 10.0;
- ufire_ise.calibrate_probe_low:
id: ufire_ise_sensor
solution: !lambda return 4.0;
@@ -0,0 +1,4 @@
packages:
i2c: !include ../../test_build_components/common/i2c/esp8266-ard.yaml
ufire_ise: !include common.yaml
actions: !include common-actions.yaml