mirror of
https://github.com/esphome/esphome.git
synced 2026-01-09 11:40:50 -07:00
[update] Add check action to trigger update checks (#12415)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -9,6 +9,8 @@ esphome:
|
||||
update.is_available:
|
||||
then:
|
||||
- logger.log: "Update available"
|
||||
else:
|
||||
- update.check:
|
||||
- update.perform:
|
||||
force_update: true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user