diff --git a/esphome/automation.py b/esphome/automation.py index 20eb9358ca..1689d29c42 100644 --- a/esphome/automation.py +++ b/esphome/automation.py @@ -127,7 +127,7 @@ def validate_potentially_or_condition(value): return validate_condition(value) -DelayAction = cg.esphome_ns.class_("DelayAction", Action, cg.Component) +DelayAction = cg.esphome_ns.class_("DelayAction", Action) LambdaAction = cg.esphome_ns.class_("LambdaAction", Action) StatelessLambdaAction = cg.esphome_ns.class_("StatelessLambdaAction", Action) IfAction = cg.esphome_ns.class_("IfAction", Action) @@ -396,7 +396,6 @@ async def delay_action_to_code( args: TemplateArgsType, ) -> MockObj: var = cg.new_Pvariable(action_id, template_arg) - await cg.register_component(var, {}) template_ = await cg.templatable(config, args, cg.uint32) cg.add(var.set_delay(template_)) return var diff --git a/esphome/core/base_automation.h b/esphome/core/base_automation.h index afd11c6867..dcad7c9d2e 100644 --- a/esphome/core/base_automation.h +++ b/esphome/core/base_automation.h @@ -178,7 +178,7 @@ class ProjectUpdateTrigger : public Trigger, public Component { }; #endif -template class DelayAction : public Action, public Component { +template class DelayAction : public Action { public: explicit DelayAction() = default; @@ -198,8 +198,8 @@ template class DelayAction : public Action, public Compon // to avoid overhead from capturing arguments by value if constexpr (sizeof...(Ts) == 0) { App.scheduler.set_timer_common_( - this, Scheduler::SchedulerItem::TIMEOUT, Scheduler::NameType::NUMERIC_ID_INTERNAL, nullptr, - static_cast(InternalSchedulerID::DELAY_ACTION), this->delay_.value(), + /* component= */ nullptr, Scheduler::SchedulerItem::TIMEOUT, Scheduler::NameType::SELF_POINTER, + /* static_name= */ reinterpret_cast(this), /* hash_or_id= */ 0, this->delay_.value(), [this]() { this->play_next_(); }, /* is_retry= */ false, /* skip_cancel= */ this->num_running_ > 1); } else { @@ -208,18 +208,18 @@ template class DelayAction : public Action, public Compon // `mutable` is required so captured copies of non-const reference args (e.g. std::string&) // are passed as non-const lvalues to play_next_(const Ts&...) where Ts may be `T&` auto f = [this, x...]() mutable { this->play_next_(x...); }; - App.scheduler.set_timer_common_(this, Scheduler::SchedulerItem::TIMEOUT, Scheduler::NameType::NUMERIC_ID_INTERNAL, - nullptr, static_cast(InternalSchedulerID::DELAY_ACTION), - this->delay_.value(x...), std::move(f), - /* is_retry= */ false, /* skip_cancel= */ this->num_running_ > 1); + App.scheduler.set_timer_common_( + /* component= */ nullptr, Scheduler::SchedulerItem::TIMEOUT, Scheduler::NameType::SELF_POINTER, + /* static_name= */ reinterpret_cast(this), /* hash_or_id= */ 0, this->delay_.value(x...), + std::move(f), + /* is_retry= */ false, /* skip_cancel= */ this->num_running_ > 1); } } - float get_setup_priority() const override { return setup_priority::HARDWARE; } void play(const Ts &...x) override { /* ignore - see play_complex */ } - void stop() override { this->cancel_timeout(InternalSchedulerID::DELAY_ACTION); } + void stop() override { App.scheduler.cancel_timeout(this); } }; template class LambdaAction : public Action {