mirror of
https://github.com/esphome/esphome.git
synced 2026-10-07 03:16:37 +00:00
[script] Disable queued script polling while the queue is empty (#18121)
This commit is contained in:
@@ -142,6 +142,9 @@ template<typename... Ts> class QueueingScript : public Script<Ts...>, public Com
|
||||
// Use std::make_unique to replace the unique_ptr
|
||||
this->var_queue_[write_pos] = std::make_unique<std::tuple<Ts...>>(x...);
|
||||
this->num_queued_++;
|
||||
// Enable loop now that there is something to dequeue - don't call loop()
|
||||
// synchronously! Let the event loop call it to avoid reentrancy issues
|
||||
this->enable_loop();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -168,6 +171,15 @@ template<typename... Ts> class QueueingScript : public Script<Ts...>, public Com
|
||||
this->queue_front_ = (this->queue_front_ + 1) % queue_capacity;
|
||||
this->trigger_tuple_(*tuple_ptr, std::make_index_sequence<sizeof...(Ts)>{});
|
||||
}
|
||||
if (this->num_queued_ == 0 && !this->is_idle()) {
|
||||
// Queue is now empty - disable loop until the next execute() queues an
|
||||
// instance. The inline is_idle() check skips the out-of-line call when
|
||||
// the loop is already disabled (execute() calls loop() synchronously).
|
||||
// This can run before this component's setup() (execute() from on_boot),
|
||||
// which leaves the state machine in LOOP_DONE and skips call_setup();
|
||||
// this class therefore must not rely on a setup() override.
|
||||
this->disable_loop();
|
||||
}
|
||||
}
|
||||
|
||||
void set_max_runs(int max_runs) { max_runs_ = max_runs; }
|
||||
|
||||
Reference in New Issue
Block a user