mirror of
https://github.com/esphome/esphome.git
synced 2025-08-07 19:07:45 +00:00
cover
This commit is contained in:
parent
a4d5f39fb6
commit
465019e510
@ -47,12 +47,19 @@ esphome:
|
|||||||
defer_order++;
|
defer_order++;
|
||||||
|
|
||||||
if (defer_order == 10) {
|
if (defer_order == 10) {
|
||||||
|
bool all_passed = set_timeout_passed && defer_passed;
|
||||||
if (defer_passed) {
|
if (defer_passed) {
|
||||||
ESP_LOGI("defer_test", "✓ Test 2 PASSED - defer() maintains FIFO order");
|
ESP_LOGI("defer_test", "✓ Test 2 PASSED - defer() maintains FIFO order");
|
||||||
ESP_LOGI("defer_test", "✓ ALL TESTS PASSED - Both set_timeout(0) and defer() maintain FIFO order");
|
if (all_passed) {
|
||||||
|
ESP_LOGI("defer_test", "✓ ALL TESTS PASSED - Both set_timeout(0) and defer() maintain FIFO order");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGE("defer_test", "✗ Test 2 FAILED - defer() executed out of order");
|
ESP_LOGE("defer_test", "✗ Test 2 FAILED - defer() executed out of order");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Publish test results
|
||||||
|
id(test_complete)->publish_state(true);
|
||||||
|
id(test_passed)->publish_state(all_passed);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -76,3 +83,11 @@ logger:
|
|||||||
level: DEBUG
|
level: DEBUG
|
||||||
|
|
||||||
api:
|
api:
|
||||||
|
|
||||||
|
binary_sensor:
|
||||||
|
- platform: template
|
||||||
|
name: "Test Complete"
|
||||||
|
id: test_complete
|
||||||
|
- platform: template
|
||||||
|
name: "Test Passed"
|
||||||
|
id: test_passed
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
|
from aioesphomeapi import BinarySensorInfo, BinarySensorState, EntityState
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from .types import APIClientConnectedFactory, RunCompiledFunction
|
from .types import APIClientConnectedFactory, RunCompiledFunction
|
||||||
@ -16,14 +17,62 @@ async def test_defer_fifo_simple(
|
|||||||
"""Test that defer() maintains FIFO order with a simple test."""
|
"""Test that defer() maintains FIFO order with a simple test."""
|
||||||
|
|
||||||
async with run_compiled(yaml_config), api_client_connected() as client:
|
async with run_compiled(yaml_config), api_client_connected() as client:
|
||||||
# Just verify we can connect and the device is running
|
# Verify we can connect
|
||||||
device_info = await client.device_info()
|
device_info = await client.device_info()
|
||||||
assert device_info is not None
|
assert device_info is not None
|
||||||
assert device_info.name == "defer-fifo-simple"
|
assert device_info.name == "defer-fifo-simple"
|
||||||
|
|
||||||
# Give the test component time to run
|
# List entities to get the keys
|
||||||
await asyncio.sleep(5)
|
entity_info, _ = await asyncio.wait_for(
|
||||||
|
client.list_entities_services(), timeout=5.0
|
||||||
|
)
|
||||||
|
|
||||||
# The component will log results, we mainly want to ensure
|
# Find our test entities
|
||||||
# it doesn't crash and completes successfully
|
test_complete_entity: BinarySensorInfo | None = None
|
||||||
print("Defer FIFO simple test completed")
|
test_passed_entity: BinarySensorInfo | None = None
|
||||||
|
|
||||||
|
for entity in entity_info:
|
||||||
|
if isinstance(entity, BinarySensorInfo):
|
||||||
|
if entity.object_id == "test_complete":
|
||||||
|
test_complete_entity = entity
|
||||||
|
elif entity.object_id == "test_passed":
|
||||||
|
test_passed_entity = entity
|
||||||
|
|
||||||
|
assert test_complete_entity is not None, "test_complete sensor not found"
|
||||||
|
assert test_passed_entity is not None, "test_passed sensor not found"
|
||||||
|
|
||||||
|
# Get the event loop
|
||||||
|
loop = asyncio.get_running_loop()
|
||||||
|
|
||||||
|
# Subscribe to state changes
|
||||||
|
states: dict[int, EntityState] = {}
|
||||||
|
test_complete_future: asyncio.Future[BinarySensorState] = loop.create_future()
|
||||||
|
test_passed_future: asyncio.Future[BinarySensorState] = loop.create_future()
|
||||||
|
|
||||||
|
def on_state(state: EntityState) -> None:
|
||||||
|
states[state.key] = state
|
||||||
|
# Check if this is our test_complete binary sensor
|
||||||
|
if isinstance(state, BinarySensorState):
|
||||||
|
if state.key == test_complete_entity.key:
|
||||||
|
if state.state and not test_complete_future.done():
|
||||||
|
test_complete_future.set_result(state)
|
||||||
|
elif state.key == test_passed_entity.key:
|
||||||
|
if not test_passed_future.done():
|
||||||
|
test_passed_future.set_result(state)
|
||||||
|
|
||||||
|
client.subscribe_states(on_state)
|
||||||
|
|
||||||
|
# Wait for test completion with timeout
|
||||||
|
try:
|
||||||
|
await asyncio.wait_for(test_complete_future, timeout=10.0)
|
||||||
|
test_passed_state = await asyncio.wait_for(test_passed_future, timeout=1.0)
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
pytest.fail(
|
||||||
|
f"Test did not complete within 10 seconds. "
|
||||||
|
f"Received states: {list(states.values())}"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Verify the test passed
|
||||||
|
assert test_passed_state.state is True, (
|
||||||
|
"FIFO test failed - items executed out of order"
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user