Build the default autorepeat timing from the schema and tidy the tests

This commit is contained in:
J. Nick Koston
2026-10-02 19:07:18 -05:00
parent 93afb0d092
commit a8e5fd0d2f
2 changed files with 25 additions and 44 deletions
@@ -7,7 +7,7 @@ import re
def test_autorepeat_timings_shared_progmem_table(
generate_main: Callable[[str], str],
) -> None:
"""Filters with identical timings share one PROGMEM table; nothing is copied."""
"""Identical timings share one PROGMEM table; an empty autorepeat gets the defaults."""
main_cpp = generate_main("tests/component_tests/binary_sensor/test_autorepeat.yaml")
tables = re.findall(
@@ -16,20 +16,8 @@ def test_autorepeat_timings_shared_progmem_table(
)
assert len(tables) == 2
shared, default = tables
assert f"AutorepeatFilter({shared}, 2);" in main_cpp
assert main_cpp.count(f"AutorepeatFilter({shared}, 2);") == 2
assert f"AutorepeatFilter({default}, 1);" in main_cpp
assert "AutorepeatFilter<" not in main_cpp
def test_autorepeat_default_timing(generate_main: Callable[[str], str]) -> None:
"""An empty autorepeat uses the documented default timing."""
main_cpp = generate_main("tests/component_tests/binary_sensor/test_autorepeat.yaml")
default = re.search(
r"AutorepeatFilterTiming (\w+)\[\] PROGMEM = \{binary_sensor::AutorepeatFilterTiming\{\n"
r" \.delay = 1000,\n \.time_off = 100,\n \.time_on = 900,\n\}\};",
main_cpp,
)
assert default is not None
assert f"AutorepeatFilter({default.group(1)}, 1);" in main_cpp
default_table = main_cpp.split(f"{default}[] PROGMEM = ", 1)[1].split(";", 1)[0]
for field in (".delay = 1000", ".time_off = 100", ".time_on = 900"):
assert field in default_table