mirror of
https://github.com/esphome/esphome.git
synced 2025-08-09 20:07:50 +00:00
cover
This commit is contained in:
parent
7100c22dc4
commit
6d24b04235
@ -67,20 +67,28 @@ script:
|
||||
ESP_LOGI("test", "Empty string timeout fired");
|
||||
});
|
||||
|
||||
// Test 5: Cancel timeout with const char* literal
|
||||
App.scheduler.set_timeout(component1, "cancel_static_timeout", 5000, []() {
|
||||
ESP_LOGI("test", "This static timeout should be cancelled");
|
||||
});
|
||||
// Cancel using const char* directly
|
||||
App.scheduler.cancel_timeout(component1, "cancel_static_timeout");
|
||||
ESP_LOGI("test", "Cancelled static timeout using const char*");
|
||||
|
||||
- id: test_dynamic_strings
|
||||
then:
|
||||
- logger.log: "Testing dynamic string timeouts and intervals"
|
||||
- lambda: |-
|
||||
auto *component2 = id(test_sensor2);
|
||||
|
||||
// Test 5: Dynamic string with set_timeout (std::string)
|
||||
// Test 6: Dynamic string with set_timeout (std::string)
|
||||
std::string dynamic_name = "dynamic_timeout_" + std::to_string(id(dynamic_counter)++);
|
||||
App.scheduler.set_timeout(component2, dynamic_name, 100, []() {
|
||||
ESP_LOGI("test", "Dynamic timeout fired");
|
||||
id(timeout_counter) += 1;
|
||||
});
|
||||
|
||||
// Test 6: Dynamic string with set_interval
|
||||
// Test 7: Dynamic string with set_interval
|
||||
std::string interval_name = "dynamic_interval_" + std::to_string(id(dynamic_counter)++);
|
||||
App.scheduler.set_interval(component2, interval_name, 250, [interval_name]() {
|
||||
ESP_LOGI("test", "Dynamic interval fired: %s", interval_name.c_str());
|
||||
@ -91,7 +99,7 @@ script:
|
||||
}
|
||||
});
|
||||
|
||||
// Test 7: Cancel with different string object but same content
|
||||
// Test 8: Cancel with different string object but same content
|
||||
std::string cancel_name = "cancel_test";
|
||||
App.scheduler.set_timeout(component2, cancel_name, 2000, []() {
|
||||
ESP_LOGI("test", "This should be cancelled");
|
||||
|
@ -25,6 +25,7 @@ async def test_scheduler_string_test(
|
||||
static_interval_fired = asyncio.Event()
|
||||
static_interval_cancelled = asyncio.Event()
|
||||
empty_string_timeout_fired = asyncio.Event()
|
||||
static_timeout_cancelled = asyncio.Event()
|
||||
dynamic_timeout_fired = asyncio.Event()
|
||||
dynamic_interval_fired = asyncio.Event()
|
||||
cancel_test_done = asyncio.Event()
|
||||
@ -67,6 +68,10 @@ async def test_scheduler_string_test(
|
||||
elif "Empty string timeout fired" in clean_line:
|
||||
empty_string_timeout_fired.set()
|
||||
|
||||
# Check for static timeout cancellation
|
||||
elif "Cancelled static timeout using const char*" in clean_line:
|
||||
static_timeout_cancelled.set()
|
||||
|
||||
# Check for dynamic string tests
|
||||
elif "Dynamic timeout fired" in clean_line:
|
||||
dynamic_timeout_fired.set()
|
||||
@ -123,6 +128,11 @@ async def test_scheduler_string_test(
|
||||
f"Expected static interval to run at least 3 times, got {static_interval_count + 1}"
|
||||
)
|
||||
|
||||
# Verify static timeout was cancelled
|
||||
assert static_timeout_cancelled.is_set(), (
|
||||
"Static timeout should have been cancelled"
|
||||
)
|
||||
|
||||
# Wait for dynamic string tests
|
||||
try:
|
||||
await asyncio.wait_for(dynamic_timeout_fired.wait(), timeout=1.0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user