mirror of
https://github.com/esphome/esphome.git
synced 2026-09-30 00:10:22 +00:00
[bluetooth_connection] Support 3 connection slots on rp2
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
esphome:
|
||||
name: poolwrap-rp2-default
|
||||
|
||||
rp2:
|
||||
board: rpipicow
|
||||
|
||||
wifi:
|
||||
ssid: MySSID
|
||||
password: password1
|
||||
|
||||
api:
|
||||
|
||||
rp2_ble_tracker:
|
||||
|
||||
bluetooth_proxy:
|
||||
@@ -0,0 +1,16 @@
|
||||
esphome:
|
||||
name: poolwrap-rp2-single
|
||||
|
||||
rp2:
|
||||
board: rpipicow
|
||||
|
||||
wifi:
|
||||
ssid: MySSID
|
||||
password: password1
|
||||
|
||||
api:
|
||||
|
||||
rp2_ble_tracker:
|
||||
|
||||
bluetooth_proxy:
|
||||
connection_slots: 1
|
||||
@@ -139,8 +139,8 @@ def test_rp2_defaults_to_the_full_proxy(
|
||||
_register_tracker(PLATFORM_RP2)
|
||||
validated = bluetooth_proxy.CONFIG_SCHEMA({})
|
||||
assert validated[CONF_ACTIVE] is True
|
||||
assert validated[bluetooth_proxy.CONF_CONNECTION_SLOTS] == 1
|
||||
assert len(validated[bluetooth_proxy.CONF_CONNECTIONS]) == 1
|
||||
assert validated[bluetooth_proxy.CONF_CONNECTION_SLOTS] == 3
|
||||
assert len(validated[bluetooth_proxy.CONF_CONNECTIONS]) == 3
|
||||
|
||||
|
||||
def test_rp2_accepts_explicit_passive(
|
||||
@@ -156,11 +156,15 @@ def test_rp2_accepts_explicit_passive(
|
||||
def test_rp2_rejects_slots_beyond_the_btstack_limit(
|
||||
set_core_config: SetCoreConfigCallable,
|
||||
) -> None:
|
||||
# The prebuilt BTstack library allows exactly one GATT client connection.
|
||||
# The BTstack pool overrides are sized for RP2_MAX_CONNECTIONS slots.
|
||||
set_core_config(PlatformFramework.RP2_ARDUINO)
|
||||
_register_tracker(PLATFORM_RP2)
|
||||
with pytest.raises(cv.Invalid, match="at most 1 connection slot"):
|
||||
bluetooth_proxy.CONFIG_SCHEMA({"connection_slots": 2})
|
||||
with pytest.raises(cv.Invalid, match="at most 3 connection slot"):
|
||||
bluetooth_proxy.CONFIG_SCHEMA({"connection_slots": 4})
|
||||
# Fewer slots than the cap stay accepted (the prebuilt single-client pool
|
||||
# path for 1, the wrap path for 2).
|
||||
validated = bluetooth_proxy.CONFIG_SCHEMA({"connection_slots": 1})
|
||||
assert len(validated[bluetooth_proxy.CONF_CONNECTIONS]) == 1
|
||||
# Values past even the loosest platform cap stop at the outer walkable
|
||||
# schema, which stays bounded for range walkers (device-builder sync);
|
||||
# in-range values get the platform message above.
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
"""The rp2 BTstack pool overrides: multi-slot builds emit the --wrap flags
|
||||
that swap the prebuilt single-client pools for the codegen-sized ones;
|
||||
single-slot builds emit none and stay byte-identical to previous releases."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
|
||||
from esphome.components import bluetooth_connection
|
||||
from esphome.core import CORE
|
||||
|
||||
from ..helpers import get_define_value
|
||||
|
||||
WRAP_FLAGS = tuple(
|
||||
f"-Wl,--wrap={symbol}" for symbol in bluetooth_connection._RP2_BTSTACK_POOL_SYMBOLS
|
||||
)
|
||||
|
||||
|
||||
def test_default_slots_emit_the_pool_wrap(
|
||||
generate_main: Callable[[str | Path], str],
|
||||
component_config_path: Callable[[str], Path],
|
||||
) -> None:
|
||||
generate_main(component_config_path("rp2_proxy_default.yaml"))
|
||||
assert all(flag in CORE.build_flags for flag in WRAP_FLAGS)
|
||||
assert get_define_value("ESPHOME_BLE_GATT_CLIENT_COUNT") == "3"
|
||||
assert get_define_value("BLUETOOTH_PROXY_MAX_CONNECTIONS") == "3"
|
||||
|
||||
|
||||
def test_single_slot_keeps_the_prebuilt_pools(
|
||||
generate_main: Callable[[str | Path], str],
|
||||
component_config_path: Callable[[str], Path],
|
||||
) -> None:
|
||||
generate_main(component_config_path("rp2_proxy_single_slot.yaml"))
|
||||
assert not any(flag in CORE.build_flags for flag in WRAP_FLAGS)
|
||||
assert get_define_value("ESPHOME_BLE_GATT_CLIENT_COUNT") == "1"
|
||||
assert get_define_value("BLUETOOTH_PROXY_MAX_CONNECTIONS") == "1"
|
||||
Reference in New Issue
Block a user