Compile the connection window out of scan-only builds; review polish

This commit is contained in:
J. Nick Koston
2026-08-21 17:08:08 -05:00
parent cc6876d776
commit 499a0b5924
8 changed files with 81 additions and 26 deletions
@@ -12,3 +12,8 @@ wifi:
esp32_ble_tracker:
scan_parameters:
window: 30ms
bluetooth_proxy:
active: true
api:
@@ -10,3 +10,8 @@ wifi:
ssid: MySSID
esp32_ble_tracker:
bluetooth_proxy:
active: true
api:
@@ -0,0 +1,12 @@
esphome:
name: scan-window-scan-only
esp32:
board: esp32dev
framework:
type: esp-idf
wifi:
ssid: MySSID
esp32_ble_tracker:
@@ -158,7 +158,7 @@ def test_connection_scan_window_above_interval_rejected(
) -> None:
stage_esp32("5.5.5", wifi=True)
with pytest.raises(
cv.Invalid, match="Connection scan window .* needs to be smaller"
cv.Invalid, match="connection_scan_window .* needs to be smaller"
):
_scan_params({"scan_parameters": {"connection_scan_window": "400ms"}})
@@ -169,7 +169,7 @@ def test_connection_scan_window_truncation_collapse_rejected(
"""A connection window that truncates into the interval's 0.625 ms unit
would silently program a full-duty scan during connections."""
stage_esp32("5.5.5", wifi=True)
with pytest.raises(cv.Invalid, match="connection window .* both truncate"):
with pytest.raises(cv.Invalid, match="connection_scan_window .* both truncate"):
_scan_params(
{
"scan_parameters": {
@@ -196,3 +196,14 @@ def test_codegen_no_connection_window_for_explicit_window(
main_cpp = generate_main(component_config_path("scan_window_explicit.yaml"))
assert "set_scan_window(48)" in main_cpp
assert "set_connection_scan_window" not in main_cpp
def test_codegen_no_connection_window_without_gatt_clients(
generate_main: Callable[[str | Path], str],
component_config_path: Callable[[str], Path],
) -> None:
"""Scan-only builds compile the connection-window path out, so the raised
default must not emit a call to the guarded setter."""
main_cpp = generate_main(component_config_path("scan_window_scan_only.yaml"))
assert "set_scan_window(512)" in main_cpp
assert "set_connection_scan_window" not in main_cpp