[update] Use the apply helpers for update.check and update.is_available (#19632)

This commit is contained in:
J. Nick Koston
2026-09-25 13:07:48 -04:00
committed by GitHub
parent eb85778a60
commit 4bb6c0f877
2 changed files with 10 additions and 43 deletions
+10 -24
View File
@@ -32,13 +32,6 @@ UpdateEntity = update_ns.class_("UpdateEntity", cg.EntityBase)
UpdateInfo = update_ns.struct("UpdateInfo")
CheckAction = update_ns.class_(
"CheckAction", automation.Action, cg.Parented.template(UpdateEntity)
)
IsAvailableCondition = update_ns.class_(
"IsAvailableCondition", automation.Condition, cg.Parented.template(UpdateEntity)
)
DEVICE_CLASSES = [
DEVICE_CLASS_EMPTY,
DEVICE_CLASS_FIRMWARE,
@@ -144,24 +137,17 @@ automation.register_apply_action(
)
automation.register_parented_action(
"update.check",
CheckAction,
automation.maybe_simple_id(
{
cv.GenerateID(): cv.use_id(UpdateEntity),
}
),
synchronous=True,
UPDATE_AUTOMATION_SCHEMA = automation.maybe_simple_id(
{
cv.GenerateID(): cv.use_id(UpdateEntity),
}
)
automation.register_parented_condition(
automation.register_apply_action(
"update.check", UPDATE_AUTOMATION_SCHEMA, automation.ApplyCall("check()")
)
automation.register_apply_condition(
"update.is_available",
IsAvailableCondition,
automation.maybe_simple_id(
{
cv.GenerateID(): cv.use_id(UpdateEntity),
}
),
UPDATE_AUTOMATION_SCHEMA,
"state == update::UPDATE_STATE_AVAILABLE",
)
-19
View File
@@ -1,19 +0,0 @@
#pragma once
#include "update_entity.h"
#include "esphome/core/automation.h"
namespace esphome::update {
template<typename... Ts> class CheckAction final : public Action<Ts...>, public Parented<UpdateEntity> {
public:
void play(const Ts &...x) override { this->parent_->check(); }
};
template<typename... Ts> class IsAvailableCondition final : public Condition<Ts...>, public Parented<UpdateEntity> {
public:
bool check(const Ts &...x) override { return this->parent_->state == UPDATE_STATE_AVAILABLE; }
};
} // namespace esphome::update