mirror of
https://github.com/esphome/esphome.git
synced 2026-10-06 19:06:37 +00:00
Merge remote-tracking branch 'upstream/dev' into integration
This commit is contained in:
@@ -232,7 +232,7 @@ lvgl:
|
||||
- roller:
|
||||
id: lv_roller
|
||||
visible_row_count: 2
|
||||
anim_time: 500ms
|
||||
anim_duration: 500ms
|
||||
options:
|
||||
- Nov
|
||||
- Dec
|
||||
@@ -317,20 +317,27 @@ lvgl:
|
||||
align: top_left
|
||||
- container:
|
||||
align: center
|
||||
anim_duration: 1s
|
||||
arc_opa: COVER
|
||||
arc_color: 0xFF0000
|
||||
arc_rounded: false
|
||||
arc_width: 3
|
||||
anim_time: 1s
|
||||
base_dir: auto
|
||||
bg_color: light_blue
|
||||
bg_grad_color: light_blue
|
||||
bg_grad_dir: hor
|
||||
bg_grad_opa: cover
|
||||
bg_grad_stop: 128
|
||||
bg_image_opa: transp
|
||||
bg_image_recolor: light_blue
|
||||
bg_image_recolor_opa: 50%
|
||||
bg_main_opa: cover
|
||||
bg_main_stop: 0
|
||||
bg_opa: 20%
|
||||
blend_mode: normal
|
||||
blur_backdrop: false
|
||||
blur_quality: auto
|
||||
blur_radius: 0
|
||||
border_color: 0x00FF00
|
||||
border_opa: cover
|
||||
border_post: true
|
||||
@@ -338,7 +345,15 @@ lvgl:
|
||||
border_width: 4
|
||||
clip_corner: false
|
||||
color_filter_opa: transp
|
||||
drop_shadow_color: 0x000000
|
||||
drop_shadow_offset_x: 5
|
||||
drop_shadow_offset_y: 5
|
||||
drop_shadow_opa: cover
|
||||
drop_shadow_quality: precision
|
||||
drop_shadow_radius: 10
|
||||
ext_click_area: 100px
|
||||
height: 50%
|
||||
image_opa: cover
|
||||
image_recolor: light_blue
|
||||
image_recolor_opa: cover
|
||||
line_width: 10
|
||||
@@ -346,6 +361,10 @@ lvgl:
|
||||
line_dash_gap: 10
|
||||
line_rounded: false
|
||||
line_color: light_blue
|
||||
margin_bottom: 4
|
||||
margin_left: 4
|
||||
margin_right: 4
|
||||
margin_top: 4
|
||||
opa: cover
|
||||
opa_layered: cover
|
||||
outline_color: light_blue
|
||||
@@ -355,8 +374,12 @@ lvgl:
|
||||
pad_all: 10px
|
||||
pad_bottom: 10px
|
||||
pad_left: 10px
|
||||
pad_radial: 0
|
||||
pad_right: 10px
|
||||
pad_top: 10px
|
||||
recolor: 0xFF0000
|
||||
recolor_opa: transp
|
||||
rotary_sensitivity: 256
|
||||
shadow_color: light_blue
|
||||
shadow_opa: cover
|
||||
shadow_spread: 5
|
||||
@@ -368,6 +391,9 @@ lvgl:
|
||||
text_letter_space: 4
|
||||
text_line_space: 4
|
||||
text_opa: cover
|
||||
text_outline_stroke_color: 0x000000
|
||||
text_outline_stroke_opa: cover
|
||||
text_outline_stroke_width: 2
|
||||
transform_rotation: 90
|
||||
transform_height: 100
|
||||
transform_pivot_x: 50%
|
||||
@@ -377,8 +403,10 @@ lvgl:
|
||||
transform_scale_y: 0.8
|
||||
transform_skew_x: 10
|
||||
transform_skew_y: 20
|
||||
transform_width: 100
|
||||
shadow_offset_x: 3
|
||||
shadow_offset_y: 3
|
||||
translate_radial: 0
|
||||
translate_x: 10
|
||||
translate_y: 10
|
||||
max_height: 100
|
||||
@@ -1053,7 +1081,7 @@ lvgl:
|
||||
- ticks:
|
||||
width: 1
|
||||
count: 61
|
||||
length: 20%
|
||||
length: 20
|
||||
radial_offset: 5
|
||||
color: 0xFFFFFF
|
||||
major:
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
esphome:
|
||||
name: test-multi-click
|
||||
|
||||
host:
|
||||
api:
|
||||
batch_delay: 0ms
|
||||
services:
|
||||
- service: run_all_tests
|
||||
then:
|
||||
# Prime the binary sensor with an initial OFF state.
|
||||
# trigger_on_initial_state defaults to false, so the first
|
||||
# state change from unknown won't fire callbacks.
|
||||
- binary_sensor.template.publish:
|
||||
id: test_button
|
||||
state: false
|
||||
- delay: 50ms
|
||||
|
||||
# Test 1: Single click (ON < 50ms, OFF >= 30ms)
|
||||
- binary_sensor.template.publish:
|
||||
id: test_button
|
||||
state: true
|
||||
- delay: 20ms
|
||||
- binary_sensor.template.publish:
|
||||
id: test_button
|
||||
state: false
|
||||
# Wait for single click trigger (30ms) + cooldown (100ms) + margin
|
||||
- delay: 200ms
|
||||
|
||||
# Test 2: Double click (ON < 50ms, OFF < 25ms, ON < 50ms, OFF >= 25ms)
|
||||
- binary_sensor.template.publish:
|
||||
id: test_button
|
||||
state: true
|
||||
- delay: 20ms
|
||||
- binary_sensor.template.publish:
|
||||
id: test_button
|
||||
state: false
|
||||
- delay: 15ms
|
||||
- binary_sensor.template.publish:
|
||||
id: test_button
|
||||
state: true
|
||||
- delay: 20ms
|
||||
- binary_sensor.template.publish:
|
||||
id: test_button
|
||||
state: false
|
||||
# Wait for double click trigger (25ms) + cooldown (100ms) + margin
|
||||
- delay: 200ms
|
||||
|
||||
# Test 3: Long press (ON >= 80ms)
|
||||
- binary_sensor.template.publish:
|
||||
id: test_button
|
||||
state: true
|
||||
- delay: 100ms
|
||||
- binary_sensor.template.publish:
|
||||
id: test_button
|
||||
state: false
|
||||
|
||||
logger:
|
||||
level: VERBOSE
|
||||
|
||||
globals:
|
||||
- id: single_click_count
|
||||
type: int
|
||||
initial_value: "0"
|
||||
- id: double_click_count
|
||||
type: int
|
||||
initial_value: "0"
|
||||
- id: long_press_count
|
||||
type: int
|
||||
initial_value: "0"
|
||||
|
||||
binary_sensor:
|
||||
- platform: template
|
||||
name: "Test Button"
|
||||
id: test_button
|
||||
on_multi_click:
|
||||
# Single press
|
||||
- timing:
|
||||
- ON for at most 50ms
|
||||
- OFF for at least 30ms
|
||||
invalid_cooldown: 100ms
|
||||
then:
|
||||
- lambda: |-
|
||||
id(single_click_count) += 1;
|
||||
ESP_LOGI("multi_click_test", "SINGLE_CLICK count=%d", id(single_click_count));
|
||||
|
||||
# Double press
|
||||
- timing:
|
||||
- ON for at most 50ms
|
||||
- OFF for at most 25ms
|
||||
- ON for at most 50ms
|
||||
- OFF for at least 25ms
|
||||
invalid_cooldown: 100ms
|
||||
then:
|
||||
- lambda: |-
|
||||
id(double_click_count) += 1;
|
||||
ESP_LOGI("multi_click_test", "DOUBLE_CLICK count=%d", id(double_click_count));
|
||||
|
||||
# Long press
|
||||
- timing:
|
||||
- ON for at least 80ms
|
||||
invalid_cooldown: 100ms
|
||||
then:
|
||||
- lambda: |-
|
||||
id(long_press_count) += 1;
|
||||
ESP_LOGI("multi_click_test", "LONG_PRESS count=%d", id(long_press_count));
|
||||
@@ -0,0 +1,82 @@
|
||||
"""Integration test for on_multi_click binary sensor automation.
|
||||
|
||||
Tests that on_multi_click correctly triggers for single click, double click,
|
||||
and long press patterns using a template binary sensor with timing
|
||||
orchestrated entirely in YAML.
|
||||
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import re
|
||||
|
||||
import pytest
|
||||
|
||||
from .types import APIClientConnectedFactory, RunCompiledFunction
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_multi_click_trigger(
|
||||
yaml_config: str,
|
||||
run_compiled: RunCompiledFunction,
|
||||
api_client_connected: APIClientConnectedFactory,
|
||||
) -> None:
|
||||
"""Test that on_multi_click triggers for single, double, and long press patterns."""
|
||||
loop = asyncio.get_running_loop()
|
||||
|
||||
single_click_pattern = re.compile(r"SINGLE_CLICK count=(\d+)")
|
||||
double_click_pattern = re.compile(r"DOUBLE_CLICK count=(\d+)")
|
||||
long_press_pattern = re.compile(r"LONG_PRESS count=(\d+)")
|
||||
|
||||
single_click_future: asyncio.Future[int] = loop.create_future()
|
||||
double_click_future: asyncio.Future[int] = loop.create_future()
|
||||
long_press_future: asyncio.Future[int] = loop.create_future()
|
||||
|
||||
def check_output(line: str) -> None:
|
||||
"""Check log output for multi-click trigger messages."""
|
||||
if m := single_click_pattern.search(line):
|
||||
if not single_click_future.done():
|
||||
single_click_future.set_result(int(m.group(1)))
|
||||
elif m := double_click_pattern.search(line):
|
||||
if not double_click_future.done():
|
||||
double_click_future.set_result(int(m.group(1)))
|
||||
elif (m := long_press_pattern.search(line)) and not long_press_future.done():
|
||||
long_press_future.set_result(int(m.group(1)))
|
||||
|
||||
async with (
|
||||
run_compiled(yaml_config, line_callback=check_output),
|
||||
api_client_connected() as client,
|
||||
):
|
||||
_entities, services = await client.list_entities_services()
|
||||
|
||||
test_service = next((s for s in services if s.name == "run_all_tests"), None)
|
||||
assert test_service is not None, "run_all_tests service not found"
|
||||
|
||||
# Kick off the entire test sequence (runs in YAML with delays)
|
||||
await client.execute_service(test_service, {})
|
||||
|
||||
# Wait for all three triggers
|
||||
try:
|
||||
count = await asyncio.wait_for(single_click_future, timeout=5.0)
|
||||
except TimeoutError:
|
||||
pytest.fail(
|
||||
"Timeout waiting for SINGLE_CLICK - on_multi_click did not trigger."
|
||||
)
|
||||
assert count == 1, f"Expected single click count=1, got {count}"
|
||||
|
||||
try:
|
||||
count = await asyncio.wait_for(double_click_future, timeout=5.0)
|
||||
except TimeoutError:
|
||||
pytest.fail(
|
||||
"Timeout waiting for DOUBLE_CLICK - on_multi_click did not trigger."
|
||||
)
|
||||
assert count == 1, f"Expected double click count=1, got {count}"
|
||||
|
||||
try:
|
||||
count = await asyncio.wait_for(long_press_future, timeout=5.0)
|
||||
except TimeoutError:
|
||||
pytest.fail(
|
||||
"Timeout waiting for LONG_PRESS - on_multi_click did not trigger."
|
||||
)
|
||||
assert count == 1, f"Expected long press count=1, got {count}"
|
||||
Reference in New Issue
Block a user