[update] Add check action to trigger update checks (#12415)

This commit is contained in:
Roger Fachini
2025-12-16 19:20:12 -08:00
committed by GitHub
parent 084f517a20
commit a065990ab9
3 changed files with 25 additions and 0 deletions

View File

@@ -29,6 +29,9 @@ 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)
)
IsAvailableCondition = update_ns.class_(
"IsAvailableCondition", automation.Condition, cg.Parented.template(UpdateEntity)
)
@@ -143,6 +146,21 @@ async def update_perform_action_to_code(config, action_id, template_arg, args):
return var
@automation.register_action(
"update.check",
CheckAction,
automation.maybe_simple_id(
{
cv.GenerateID(): cv.use_id(UpdateEntity),
}
),
)
async def update_check_action_to_code(config, action_id, template_arg, args):
var = cg.new_Pvariable(action_id, template_arg)
await cg.register_parented(var, config[CONF_ID])
return var
@automation.register_condition(
"update.is_available",
IsAvailableCondition,

View File

@@ -14,6 +14,11 @@ template<typename... Ts> class PerformAction : public Action<Ts...>, public Pare
void play(const Ts &...x) override { this->parent_->perform(this->force_.value(x...)); }
};
template<typename... Ts> class CheckAction : public Action<Ts...>, public Parented<UpdateEntity> {
public:
void play(const Ts &...x) override { this->parent_->check(); }
};
template<typename... Ts> class IsAvailableCondition : public Condition<Ts...>, public Parented<UpdateEntity> {
public:
bool check(const Ts &...x) override { return this->parent_->state == UPDATE_STATE_AVAILABLE; }

View File

@@ -9,6 +9,8 @@ esphome:
update.is_available:
then:
- logger.log: "Update available"
else:
- update.check:
- update.perform:
force_update: true