[pipsolar] Use register_apply_action for output.pipsolar.set_level (#19685)

This commit is contained in:
J. Nick Koston
2026-09-25 20:30:12 -04:00
committed by GitHub
parent 5043e12690
commit d34b21cb7e
4 changed files with 17 additions and 29 deletions
+2 -17
View File
@@ -3,8 +3,6 @@ import esphome.codegen as cg
from esphome.components import output
import esphome.config_validation as cv
from esphome.const import CONF_ID, CONF_VALUE
from esphome.core import ID
from esphome.cpp_generator import MockObj, TemplateArgsType
from esphome.types import ConfigType
from .. import CONF_PIPSOLAR_ID, PIPSOLAR_COMPONENT_SCHEMA, pipsolar_ns
@@ -12,7 +10,6 @@ from .. import CONF_PIPSOLAR_ID, PIPSOLAR_COMPONENT_SCHEMA, pipsolar_ns
DEPENDENCIES = ["pipsolar"]
PipsolarOutput = pipsolar_ns.class_("PipsolarOutput", output.FloatOutput)
SetOutputAction = pipsolar_ns.class_("SetOutputAction", automation.Action)
CONF_POSSIBLE_VALUES = "possible_values"
@@ -92,25 +89,13 @@ async def to_code(config: ConfigType) -> None:
cg.add(var.set_possible_values(conf[CONF_POSSIBLE_VALUES]))
@automation.register_action(
automation.register_apply_action(
"output.pipsolar.set_level",
SetOutputAction,
cv.Schema(
{
cv.Required(CONF_ID): cv.use_id(PipsolarOutput),
cv.Required(CONF_VALUE): cv.templatable(cv.positive_float),
}
),
synchronous=True,
automation.ApplyField(CONF_VALUE, "set_value", cg.float_),
)
async def output_pipsolar_set_level_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_VALUE], args, cg.float_)
cg.add(var.set_level(template_))
return var
@@ -27,16 +27,4 @@ class PipsolarOutput final : public output::FloatOutput {
std::vector<float> possible_values_;
};
template<typename... Ts> class SetOutputAction final : public Action<Ts...> {
public:
SetOutputAction(PipsolarOutput *output) : output_(output) {}
TEMPLATABLE_VALUE(float, level)
void play(const Ts &...x) override { this->output_->set_value(this->level_.value(x...)); }
protected:
PipsolarOutput *output_;
};
} // namespace esphome::pipsolar
@@ -0,0 +1,7 @@
button:
- platform: template
name: Pipsolar Set Level
on_press:
- output.pipsolar.set_level:
id: inverter0_battery_recharge_voltage_out
value: !lambda return 49.0;
@@ -0,0 +1,8 @@
substitutions:
tx_pin: GPIO0
rx_pin: GPIO2
packages:
uart: !include ../../test_build_components/common/uart/esp8266-ard.yaml
pipsolar: !include common.yaml
actions: !include common-actions.yaml