From 872388f6e36c72f99b0611f072833aaf479a535c Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 15 Jun 2025 20:43:01 -0500 Subject: [PATCH] tests, address review comments --- .../loop_test_component/__init__.py | 3 +- .../loop_test_component.cpp | 43 +++++++++++++++++++ .../loop_test_component/loop_test_component.h | 40 +++-------------- 3 files changed, 49 insertions(+), 37 deletions(-) create mode 100644 tests/integration/fixtures/external_components/loop_test_component/loop_test_component.cpp diff --git a/tests/integration/fixtures/external_components/loop_test_component/__init__.py b/tests/integration/fixtures/external_components/loop_test_component/__init__.py index 9e5a46aa37..c5eda67d1e 100644 --- a/tests/integration/fixtures/external_components/loop_test_component/__init__.py +++ b/tests/integration/fixtures/external_components/loop_test_component/__init__.py @@ -1,7 +1,7 @@ from esphome import automation import esphome.codegen as cg import esphome.config_validation as cv -from esphome.const import CONF_ID, CONF_NAME +from esphome.const import CONF_COMPONENTS, CONF_ID, CONF_NAME CODEOWNERS = ["@esphome/tests"] @@ -10,7 +10,6 @@ LoopTestComponent = loop_test_component_ns.class_("LoopTestComponent", cg.Compon CONF_DISABLE_AFTER = "disable_after" CONF_TEST_REDUNDANT_OPERATIONS = "test_redundant_operations" -CONF_COMPONENTS = "components" COMPONENT_CONFIG_SCHEMA = cv.Schema( { diff --git a/tests/integration/fixtures/external_components/loop_test_component/loop_test_component.cpp b/tests/integration/fixtures/external_components/loop_test_component/loop_test_component.cpp new file mode 100644 index 0000000000..01abdb6566 --- /dev/null +++ b/tests/integration/fixtures/external_components/loop_test_component/loop_test_component.cpp @@ -0,0 +1,43 @@ +#include "loop_test_component.h" + +namespace esphome { +namespace loop_test_component { + +void LoopTestComponent::setup() { ESP_LOGI(TAG, "[%s] Setup called", this->name_.c_str()); } + +void LoopTestComponent::loop() { + this->loop_count_++; + ESP_LOGI(TAG, "[%s] Loop count: %d", this->name_.c_str(), this->loop_count_); + + // Test self-disable after specified count + if (this->disable_after_ > 0 && this->loop_count_ == this->disable_after_) { + ESP_LOGI(TAG, "[%s] Disabling self after %d loops", this->name_.c_str(), this->disable_after_); + this->disable_loop(); + } + + // Test redundant operations + if (this->test_redundant_operations_ && this->loop_count_ == 5) { + if (this->name_ == "redundant_enable") { + ESP_LOGI(TAG, "[%s] Testing enable when already enabled", this->name_.c_str()); + this->enable_loop(); + } else if (this->name_ == "redundant_disable") { + ESP_LOGI(TAG, "[%s] Testing disable when will be disabled", this->name_.c_str()); + // We'll disable at count 10, but try to disable again at 5 + this->disable_loop(); + ESP_LOGI(TAG, "[%s] First disable complete", this->name_.c_str()); + } + } +} + +void LoopTestComponent::service_enable() { + ESP_LOGI(TAG, "[%s] Service enable called", this->name_.c_str()); + this->enable_loop(); +} + +void LoopTestComponent::service_disable() { + ESP_LOGI(TAG, "[%s] Service disable called", this->name_.c_str()); + this->disable_loop(); +} + +} // namespace loop_test_component +} // namespace esphome \ No newline at end of file diff --git a/tests/integration/fixtures/external_components/loop_test_component/loop_test_component.h b/tests/integration/fixtures/external_components/loop_test_component/loop_test_component.h index b663ea814e..5c43dd4b43 100644 --- a/tests/integration/fixtures/external_components/loop_test_component/loop_test_component.h +++ b/tests/integration/fixtures/external_components/loop_test_component/loop_test_component.h @@ -16,42 +16,12 @@ class LoopTestComponent : public Component { void set_disable_after(int count) { this->disable_after_ = count; } void set_test_redundant_operations(bool test) { this->test_redundant_operations_ = test; } - void setup() override { ESP_LOGI(TAG, "[%s] Setup called", this->name_.c_str()); } - - void loop() override { - this->loop_count_++; - ESP_LOGI(TAG, "[%s] Loop count: %d", this->name_.c_str(), this->loop_count_); - - // Test self-disable after specified count - if (this->disable_after_ > 0 && this->loop_count_ == this->disable_after_) { - ESP_LOGI(TAG, "[%s] Disabling self after %d loops", this->name_.c_str(), this->disable_after_); - this->disable_loop(); - } - - // Test redundant operations - if (this->test_redundant_operations_ && this->loop_count_ == 5) { - if (this->name_ == "redundant_enable") { - ESP_LOGI(TAG, "[%s] Testing enable when already enabled", this->name_.c_str()); - this->enable_loop(); - } else if (this->name_ == "redundant_disable") { - ESP_LOGI(TAG, "[%s] Testing disable when will be disabled", this->name_.c_str()); - // We'll disable at count 10, but try to disable again at 5 - this->disable_loop(); - ESP_LOGI(TAG, "[%s] First disable complete", this->name_.c_str()); - } - } - } + void setup() override; + void loop() override; // Service methods for external control - void service_enable() { - ESP_LOGI(TAG, "[%s] Service enable called", this->name_.c_str()); - this->enable_loop(); - } - - void service_disable() { - ESP_LOGI(TAG, "[%s] Service disable called", this->name_.c_str()); - this->disable_loop(); - } + void service_enable(); + void service_disable(); int get_loop_count() const { return this->loop_count_; } @@ -85,4 +55,4 @@ template class DisableAction : public Action { }; } // namespace loop_test_component -} // namespace esphome \ No newline at end of file +} // namespace esphome