[sensor] Merge the radar timeout and throttle filters into one (#20118)

This commit is contained in:
J. Nick Koston
2026-10-09 09:19:22 -10:00
committed by GitHub
parent 456e3d8979
commit 94e6bd90d8
11 changed files with 333 additions and 274 deletions
@@ -0,0 +1,24 @@
"""timeout (value last) followed by throttle_with_priority with the same period becomes one filter."""
from collections.abc import Callable
from pathlib import Path
import re
def test_timeout_throttle_pair_is_merged(
generate_main: Callable[[str | Path], str],
) -> None:
main_cpp = generate_main("tests/component_tests/sensor/timeout_throttle.yaml")
# Only the `merged` sensor's adjacent pair becomes one object
assert (
len(re.findall(r"new\(\w+\) sensor::TimeoutThrottleFilter\(1000\);", main_cpp))
== 1
)
merged = re.search(r"merged->set_filters\(\{(\w+)\}\);", main_cpp)
assert merged is not None
assert f"new({merged.group(1)}) sensor::TimeoutThrottleFilter(1000);" in main_cpp
# Every other shape keeps its two filters
for sensor_id in ("other_periods", "other_order", "value_list", "configured_value"):
call = re.search(rf"{sensor_id}->set_filters\(\{{([^}}]*)\}}\);", main_cpp)
assert call is not None and len(call.group(1).split(",")) == 2, sensor_id
@@ -0,0 +1,52 @@
esphome:
name: test
esp32:
board: esp32dev
sensor:
- platform: template
id: merged
filters:
- timeout:
timeout: 1s
value: last
- throttle_with_priority: 1s
- platform: template
id: other_periods
filters:
- timeout:
timeout: 1s
value: last
- throttle_with_priority: 2s
- platform: template
id: other_order
filters:
- throttle_with_priority: 1s
- timeout:
timeout: 1s
value: last
- platform: template
id: value_list
filters:
- timeout:
timeout: 1s
value: last
- throttle_with_priority:
timeout: 1s
value: [0.0]
- platform: template
id: configured_value
filters:
- timeout:
timeout: 1s
value: 0.0
- throttle_with_priority: 1s
- platform: template
id: inside_or
filters:
- or:
- timeout:
timeout: 1s
value: last
- throttle_with_priority: 1s