[binary_sensor] Share multi click timing tables in flash and skip the default cooldown setter (#20071)

This commit is contained in:
J. Nick Koston
2026-10-12 13:39:10 -10:00
committed by GitHub
parent 318e4b79c1
commit 331d12af2f
5 changed files with 106 additions and 48 deletions
@@ -0,0 +1,29 @@
"""Tests for the multi click trigger codegen."""
from collections.abc import Callable
from pathlib import Path
import re
def test_multi_click_timing_tables(generate_main: Callable[[str | Path], str]) -> None:
"""Identical timings share one PROGMEM table; the default cooldown is not set."""
main_cpp = generate_main(
"tests/component_tests/binary_sensor/test_multi_click.yaml"
)
tables = re.findall(
r"static constexpr binary_sensor::MultiClickTriggerEvent (\w+)\[\] PROGMEM",
main_cpp,
)
assert len(tables) == 2
single, long_press = tables
triggers = re.findall(
r"binary_sensor::MultiClickTrigger\((\w+), (\w+), (\d+)\);", main_cpp
)
assert triggers == [
("button_a", single, "2"),
("button_a", long_press, "1"),
("button_b", single, "2"),
]
assert main_cpp.count("set_invalid_cooldown(") == 1
assert "set_invalid_cooldown(500);" in main_cpp
@@ -0,0 +1,33 @@
---
esphome:
name: test
esp32:
board: esp32dev
logger:
binary_sensor:
- platform: gpio
id: button_a
pin: GPIO32
on_multi_click:
- timing:
- ON for at most 1s
- OFF for at least 0.25s
then:
- logger.log: a single
- timing:
- ON for at least 2s
invalid_cooldown: 500ms
then:
- logger.log: a long
- platform: gpio
id: button_b
pin: GPIO33
on_multi_click:
- timing:
- ON for at most 1s
- OFF for at least 0.25s
then:
- logger.log: b single