1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-15 01:32:19 +01:00

Merge remote-tracking branch 'origin/loop_done' into integration

This commit is contained in:
J. Nick Koston
2025-06-15 20:44:24 -05:00
5 changed files with 51 additions and 39 deletions

View File

@@ -54,7 +54,7 @@ void Sensor::publish_state(float state) {
void Sensor::add_on_state_callback(std::function<void(float)> &&callback) { this->callback_.add(std::move(callback)); } void Sensor::add_on_state_callback(std::function<void(float)> &&callback) { this->callback_.add(std::move(callback)); }
void Sensor::add_on_raw_state_callback(std::function<void(float)> &&callback) { void Sensor::add_on_raw_state_callback(std::function<void(float)> &&callback) {
if (!this->raw_callback_) { if (!this->raw_callback_) {
this->raw_callback_ = std::make_unique<CallbackManager<void(float)>>(); this->raw_callback_ = make_unique<CallbackManager<void(float)>>();
} }
this->raw_callback_->add(std::move(callback)); this->raw_callback_->add(std::move(callback));
} }

View File

@@ -56,7 +56,7 @@ void TextSensor::add_on_state_callback(std::function<void(std::string)> callback
} }
void TextSensor::add_on_raw_state_callback(std::function<void(std::string)> callback) { void TextSensor::add_on_raw_state_callback(std::function<void(std::string)> callback) {
if (!this->raw_callback_) { if (!this->raw_callback_) {
this->raw_callback_ = std::make_unique<CallbackManager<void(std::string)>>(); this->raw_callback_ = make_unique<CallbackManager<void(std::string)>>();
} }
this->raw_callback_->add(std::move(callback)); this->raw_callback_->add(std::move(callback));
} }

View File

@@ -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(
{ {

View File

@@ -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

View File

@@ -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