From b7b1507dafc8f403c6a377409ab0d8505e71bbc6 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 23 Sep 2026 23:28:03 +0100 Subject: [PATCH] [update] Use register_apply_action for update.perform (#19505) --- esphome/components/update/__init__.py | 20 ++------------------ esphome/components/update/automation.h | 7 ------- tests/components/update/common.yaml | 2 ++ 3 files changed, 4 insertions(+), 25 deletions(-) diff --git a/esphome/components/update/__init__.py b/esphome/components/update/__init__.py index 5ebe58881d..818358c48a 100644 --- a/esphome/components/update/__init__.py +++ b/esphome/components/update/__init__.py @@ -32,9 +32,6 @@ UpdateEntity = update_ns.class_("UpdateEntity", cg.EntityBase) UpdateInfo = update_ns.struct("UpdateInfo") -PerformAction = update_ns.class_( - "PerformAction", automation.Action, cg.Parented.template(UpdateEntity) -) CheckAction = update_ns.class_( "CheckAction", automation.Action, cg.Parented.template(UpdateEntity) ) @@ -133,9 +130,8 @@ async def to_code(config: ConfigType) -> None: cg.add_global(update_ns.using) -@automation.register_action( +automation.register_apply_action( "update.perform", - PerformAction, automation.maybe_simple_id( { cv.GenerateID(): cv.use_id(UpdateEntity), @@ -144,20 +140,8 @@ async def to_code(config: ConfigType) -> None: ): cv.templatable(cv.boolean), } ), - synchronous=True, + automation.ApplyField(CONF_FORCE_UPDATE, "perform", cg.bool_), ) -async def update_perform_action_to_code( - config: ConfigType, - action_id: ID, - template_arg: cg.TemplateArguments, - args: TemplateArgsType, -) -> MockObj: - var = cg.new_Pvariable(action_id, template_arg) - await cg.register_parented(var, config[CONF_ID]) - - force = await cg.templatable(config[CONF_FORCE_UPDATE], args, cg.bool_) - cg.add(var.set_force(force)) - return var @automation.register_action( diff --git a/esphome/components/update/automation.h b/esphome/components/update/automation.h index 8ba7b71a9c..3d303fdb63 100644 --- a/esphome/components/update/automation.h +++ b/esphome/components/update/automation.h @@ -6,13 +6,6 @@ namespace esphome::update { -template class PerformAction final : public Action, public Parented { - TEMPLATABLE_VALUE(bool, force) - - public: - void play(const Ts &...x) override { this->parent_->perform(this->force_.value(x...)); } -}; - template class CheckAction final : public Action, public Parented { public: void play(const Ts &...x) override { this->parent_->check(); } diff --git a/tests/components/update/common.yaml b/tests/components/update/common.yaml index 40042945c8..bcfdbd8c0b 100644 --- a/tests/components/update/common.yaml +++ b/tests/components/update/common.yaml @@ -13,6 +13,8 @@ esphome: - update.check: - update.perform: force_update: true + - update.perform: + force_update: !lambda return false; wifi: ssid: MySSID