1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-22 19:53:46 +01:00

address review comments

This commit is contained in:
J. Nick Koston
2025-10-16 15:51:01 -10:00
parent f2ec2c3fbf
commit 2e30a4953a
3 changed files with 11 additions and 5 deletions

View File

@@ -54,7 +54,7 @@ def check_max_runs(value):
if value[CONF_MODE] not in [CONF_QUEUED, CONF_PARALLEL]: if value[CONF_MODE] not in [CONF_QUEUED, CONF_PARALLEL]:
raise cv.Invalid( raise cv.Invalid(
"The option 'max_runs' is only valid in 'queue' and 'parallel' mode.", "The option 'max_runs' is only valid in 'queued' and 'parallel' mode.",
path=[CONF_MAX_RUNS], path=[CONF_MAX_RUNS],
) )

View File

@@ -1,5 +1,7 @@
#pragma once #pragma once
#include <memory>
#include <tuple>
#include "esphome/core/automation.h" #include "esphome/core/automation.h"
#include "esphome/core/component.h" #include "esphome/core/component.h"
#include "esphome/core/helpers.h" #include "esphome/core/helpers.h"
@@ -137,6 +139,10 @@ template<typename... Ts> class QueueingScript : public Script<Ts...>, public Com
} }
void stop() override { void stop() override {
// Clear all queued items to free memory immediately
for (int i = 0; i < this->max_runs_ - 1; i++) {
this->var_queue_[i].reset();
}
this->num_queued_ = 0; this->num_queued_ = 0;
this->queue_front_ = 0; this->queue_front_ = 0;
Script<Ts...>::stop(); Script<Ts...>::stop();
@@ -144,11 +150,11 @@ template<typename... Ts> class QueueingScript : public Script<Ts...>, public Com
void loop() override { void loop() override {
if (this->num_queued_ != 0 && !this->is_action_running()) { if (this->num_queued_ != 0 && !this->is_action_running()) {
// Dequeue: decrement count, read from front, advance read position // Dequeue: decrement count, move tuple out (frees slot), advance read position
this->num_queued_--; this->num_queued_--;
auto &vars = *this->var_queue_[this->queue_front_]; auto tuple_ptr = std::move(this->var_queue_[this->queue_front_]);
this->queue_front_ = (this->queue_front_ + 1) % (this->max_runs_ - 1); this->queue_front_ = (this->queue_front_ + 1) % (this->max_runs_ - 1);
this->trigger_tuple_(vars, typename gens<sizeof...(Ts)>::type()); this->trigger_tuple_(*tuple_ptr, typename gens<sizeof...(Ts)>::type());
} }
} }

View File

@@ -135,7 +135,7 @@ async def test_script_queued(
api_client_connected() as client, api_client_connected() as client,
): ):
# Get services # Get services
entities, services = await client.list_entities_services() _, services = await client.list_entities_services()
# Test 1: Queue depth limit # Test 1: Queue depth limit
test_service = next((s for s in services if s.name == "test_queue_depth"), None) test_service = next((s for s in services if s.name == "test_queue_depth"), None)