mirror of
https://github.com/esphome/esphome.git
synced 2026-10-07 11:26:39 +00:00
adl tests
This commit is contained in:
@@ -55,3 +55,31 @@ select:
|
|||||||
- lambda: |-
|
- lambda: |-
|
||||||
std::string prefix = x.substr(0, 6);
|
std::string prefix = x.substr(0, 6);
|
||||||
ESP_LOGI("test", "Substr prefix: %s", prefix.c_str());
|
ESP_LOGI("test", "Substr prefix: %s", prefix.c_str());
|
||||||
|
|
||||||
|
# Second select with numeric options to test ADL functions
|
||||||
|
- platform: template
|
||||||
|
name: "Baud Rate"
|
||||||
|
id: baud_select
|
||||||
|
optimistic: true
|
||||||
|
options:
|
||||||
|
- "9600"
|
||||||
|
- "115200"
|
||||||
|
initial_option: "9600"
|
||||||
|
on_value:
|
||||||
|
then:
|
||||||
|
# Test 9: stoi via ADL
|
||||||
|
- lambda: |-
|
||||||
|
int baud = stoi(x);
|
||||||
|
ESP_LOGI("test", "stoi result: %d", baud);
|
||||||
|
# Test 10: stol via ADL
|
||||||
|
- lambda: |-
|
||||||
|
long baud_long = stol(x);
|
||||||
|
ESP_LOGI("test", "stol result: %ld", baud_long);
|
||||||
|
# Test 11: stof via ADL
|
||||||
|
- lambda: |-
|
||||||
|
float baud_float = stof(x);
|
||||||
|
ESP_LOGI("test", "stof result: %.0f", baud_float);
|
||||||
|
# Test 12: stod via ADL
|
||||||
|
- lambda: |-
|
||||||
|
double baud_double = stod(x);
|
||||||
|
ESP_LOGI("test", "stod result: %.0f", baud_double);
|
||||||
|
|||||||
@@ -28,6 +28,11 @@ async def test_select_stringref_trigger(
|
|||||||
find_substr_future = loop.create_future()
|
find_substr_future = loop.create_future()
|
||||||
find_char_future = loop.create_future()
|
find_char_future = loop.create_future()
|
||||||
substr_future = loop.create_future()
|
substr_future = loop.create_future()
|
||||||
|
# ADL functions
|
||||||
|
stoi_future = loop.create_future()
|
||||||
|
stol_future = loop.create_future()
|
||||||
|
stof_future = loop.create_future()
|
||||||
|
stod_future = loop.create_future()
|
||||||
|
|
||||||
# Patterns to match in logs
|
# Patterns to match in logs
|
||||||
value_pattern = re.compile(r"Select value: Option B")
|
value_pattern = re.compile(r"Select value: Option B")
|
||||||
@@ -38,6 +43,11 @@ async def test_select_stringref_trigger(
|
|||||||
find_substr_pattern = re.compile(r"Found 'Option' in value")
|
find_substr_pattern = re.compile(r"Found 'Option' in value")
|
||||||
find_char_pattern = re.compile(r"Space at position: 6") # space at index 6
|
find_char_pattern = re.compile(r"Space at position: 6") # space at index 6
|
||||||
substr_pattern = re.compile(r"Substr prefix: Option")
|
substr_pattern = re.compile(r"Substr prefix: Option")
|
||||||
|
# ADL function patterns (115200 from baud rate select)
|
||||||
|
stoi_pattern = re.compile(r"stoi result: 115200")
|
||||||
|
stol_pattern = re.compile(r"stol result: 115200")
|
||||||
|
stof_pattern = re.compile(r"stof result: 115200")
|
||||||
|
stod_pattern = re.compile(r"stod result: 115200")
|
||||||
|
|
||||||
def check_output(line: str) -> None:
|
def check_output(line: str) -> None:
|
||||||
"""Check log output for expected messages."""
|
"""Check log output for expected messages."""
|
||||||
@@ -57,6 +67,15 @@ async def test_select_stringref_trigger(
|
|||||||
find_char_future.set_result(True)
|
find_char_future.set_result(True)
|
||||||
if not substr_future.done() and substr_pattern.search(line):
|
if not substr_future.done() and substr_pattern.search(line):
|
||||||
substr_future.set_result(True)
|
substr_future.set_result(True)
|
||||||
|
# ADL functions
|
||||||
|
if not stoi_future.done() and stoi_pattern.search(line):
|
||||||
|
stoi_future.set_result(True)
|
||||||
|
if not stol_future.done() and stol_pattern.search(line):
|
||||||
|
stol_future.set_result(True)
|
||||||
|
if not stof_future.done() and stof_pattern.search(line):
|
||||||
|
stof_future.set_result(True)
|
||||||
|
if not stod_future.done() and stod_pattern.search(line):
|
||||||
|
stod_future.set_result(True)
|
||||||
|
|
||||||
async with (
|
async with (
|
||||||
run_compiled(yaml_config, line_callback=check_output),
|
run_compiled(yaml_config, line_callback=check_output),
|
||||||
@@ -76,8 +95,16 @@ async def test_select_stringref_trigger(
|
|||||||
)
|
)
|
||||||
assert select_entity is not None, "Test Select entity not found"
|
assert select_entity is not None, "Test Select entity not found"
|
||||||
|
|
||||||
|
baud_entity = next(
|
||||||
|
(e for e in entities if hasattr(e, "options") and e.name == "Baud Rate"),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
assert baud_entity is not None, "Baud Rate entity not found"
|
||||||
|
|
||||||
# Change select to Option B - this should trigger on_value with StringRef
|
# Change select to Option B - this should trigger on_value with StringRef
|
||||||
client.select_command(select_entity.key, "Option B")
|
client.select_command(select_entity.key, "Option B")
|
||||||
|
# Change baud to 115200 - this tests ADL functions (stoi, stol, stof, stod)
|
||||||
|
client.select_command(baud_entity.key, "115200")
|
||||||
|
|
||||||
# Wait for all log messages confirming StringRef operations work
|
# Wait for all log messages confirming StringRef operations work
|
||||||
try:
|
try:
|
||||||
@@ -91,6 +118,10 @@ async def test_select_stringref_trigger(
|
|||||||
find_substr_future,
|
find_substr_future,
|
||||||
find_char_future,
|
find_char_future,
|
||||||
substr_future,
|
substr_future,
|
||||||
|
stoi_future,
|
||||||
|
stol_future,
|
||||||
|
stof_future,
|
||||||
|
stod_future,
|
||||||
),
|
),
|
||||||
timeout=5.0,
|
timeout=5.0,
|
||||||
)
|
)
|
||||||
@@ -104,5 +135,9 @@ async def test_select_stringref_trigger(
|
|||||||
"find_substr": find_substr_future.done(),
|
"find_substr": find_substr_future.done(),
|
||||||
"find_char": find_char_future.done(),
|
"find_char": find_char_future.done(),
|
||||||
"substr": substr_future.done(),
|
"substr": substr_future.done(),
|
||||||
|
"stoi": stoi_future.done(),
|
||||||
|
"stol": stol_future.done(),
|
||||||
|
"stof": stof_future.done(),
|
||||||
|
"stod": stod_future.done(),
|
||||||
}
|
}
|
||||||
pytest.fail(f"StringRef operations failed - received: {results}")
|
pytest.fail(f"StringRef operations failed - received: {results}")
|
||||||
|
|||||||
Reference in New Issue
Block a user