mirror of
https://github.com/esphome/esphome.git
synced 2026-10-14 10:12:52 +00:00
Merge remote-tracking branch 'origin/dev' into esp8266-entity-names-flash
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user