mirror of
https://github.com/esphome/esphome.git
synced 2025-09-14 17:22:20 +01:00
tests, address review comments
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
from esphome import automation
|
from esphome import automation
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
import esphome.config_validation as cv
|
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"]
|
CODEOWNERS = ["@esphome/tests"]
|
||||||
|
|
||||||
@@ -10,7 +10,6 @@ LoopTestComponent = loop_test_component_ns.class_("LoopTestComponent", cg.Compon
|
|||||||
|
|
||||||
CONF_DISABLE_AFTER = "disable_after"
|
CONF_DISABLE_AFTER = "disable_after"
|
||||||
CONF_TEST_REDUNDANT_OPERATIONS = "test_redundant_operations"
|
CONF_TEST_REDUNDANT_OPERATIONS = "test_redundant_operations"
|
||||||
CONF_COMPONENTS = "components"
|
|
||||||
|
|
||||||
COMPONENT_CONFIG_SCHEMA = cv.Schema(
|
COMPONENT_CONFIG_SCHEMA = cv.Schema(
|
||||||
{
|
{
|
||||||
|
@@ -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
|
@@ -16,42 +16,12 @@ class LoopTestComponent : public Component {
|
|||||||
void set_disable_after(int count) { this->disable_after_ = count; }
|
void set_disable_after(int count) { this->disable_after_ = count; }
|
||||||
void set_test_redundant_operations(bool test) { this->test_redundant_operations_ = test; }
|
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 setup() override;
|
||||||
|
void loop() override;
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Service methods for external control
|
// Service methods for external control
|
||||||
void service_enable() {
|
void service_enable();
|
||||||
ESP_LOGI(TAG, "[%s] Service enable called", this->name_.c_str());
|
void service_disable();
|
||||||
this->enable_loop();
|
|
||||||
}
|
|
||||||
|
|
||||||
void service_disable() {
|
|
||||||
ESP_LOGI(TAG, "[%s] Service disable called", this->name_.c_str());
|
|
||||||
this->disable_loop();
|
|
||||||
}
|
|
||||||
|
|
||||||
int get_loop_count() const { return this->loop_count_; }
|
int get_loop_count() const { return this->loop_count_; }
|
||||||
|
|
||||||
@@ -85,4 +55,4 @@ template<typename... Ts> class DisableAction : public Action<Ts...> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
} // namespace loop_test_component
|
} // namespace loop_test_component
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
Reference in New Issue
Block a user