mirror of
https://github.com/esphome/esphome.git
synced 2026-10-01 08:50:22 +00:00
[ble_nus] Increase BLE MTU for NUS (#19629)
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: J. Nick Koston <nick@home-assistant.io>
This commit is contained in:
co-authored by
pre-commit-ci-lite[bot]
J. Nick Koston
parent
1183beb1fb
commit
a000ce90bc
@@ -0,0 +1,8 @@
|
||||
esphome:
|
||||
name: mtutest
|
||||
|
||||
nrf52:
|
||||
board: adafruit_itsybitsy_nrf52840
|
||||
bootloader: adafruit_nrf52_sd140_v6
|
||||
|
||||
zephyr_ble_server:
|
||||
@@ -0,0 +1,11 @@
|
||||
esphome:
|
||||
name: mtutest
|
||||
|
||||
nrf52:
|
||||
board: adafruit_itsybitsy_nrf52840
|
||||
bootloader: adafruit_nrf52_sd140_v6
|
||||
|
||||
logger:
|
||||
|
||||
ble_nus:
|
||||
type: logs
|
||||
@@ -0,0 +1,18 @@
|
||||
esphome:
|
||||
name: mtutest
|
||||
|
||||
nrf52:
|
||||
board: adafruit_itsybitsy_nrf52840
|
||||
bootloader: adafruit_nrf52_sd140_v6
|
||||
|
||||
logger:
|
||||
|
||||
zephyr_ble_server:
|
||||
|
||||
ble_nus:
|
||||
type: logs
|
||||
|
||||
ota:
|
||||
- platform: zephyr_mcumgr
|
||||
transport:
|
||||
ble: true
|
||||
@@ -0,0 +1,52 @@
|
||||
"""Tests for the BLE L2CAP MTU that zephyr_ble_server writes to prj.conf."""
|
||||
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from esphome.components.zephyr import zephyr_data
|
||||
from esphome.components.zephyr.const import KEY_PRJ_CONF
|
||||
from esphome.components.zephyr_ble_server import _emit_ble_mtu, request_ble_l2cap_mtu
|
||||
|
||||
MTU_KEYS = (
|
||||
"CONFIG_BT_L2CAP_TX_MTU",
|
||||
"CONFIG_BT_BUF_ACL_TX_SIZE",
|
||||
"CONFIG_BT_BUF_ACL_RX_SIZE",
|
||||
)
|
||||
|
||||
|
||||
def _mtu_values() -> tuple[int | None, ...]:
|
||||
prj_conf = zephyr_data()[KEY_PRJ_CONF][""]
|
||||
return tuple(prj_conf.get(key, (None,))[0] for key in MTU_KEYS)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("fixture", "expected"),
|
||||
[
|
||||
("no_request.yaml", (None, None, None)),
|
||||
("nus.yaml", (247, 251, 251)),
|
||||
# The largest request wins; only the TX buffer is capped at 251
|
||||
("nus_mcumgr.yaml", (498, 251, 502)),
|
||||
],
|
||||
)
|
||||
def test_l2cap_mtu_prj_conf(
|
||||
fixture: str,
|
||||
expected: tuple[int | None, ...],
|
||||
generate_main: Callable[[str | Path], str],
|
||||
component_config_path: Callable[[str], Path],
|
||||
) -> None:
|
||||
generate_main(component_config_path(fixture))
|
||||
assert _mtu_values() == expected
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_request_after_emit_raises(
|
||||
generate_main: Callable[[str | Path], str],
|
||||
component_config_path: Callable[[str], Path],
|
||||
) -> None:
|
||||
generate_main(component_config_path("no_request.yaml"))
|
||||
request_ble_l2cap_mtu(247)
|
||||
await _emit_ble_mtu()
|
||||
with pytest.raises(RuntimeError, match="after it was written"):
|
||||
request_ble_l2cap_mtu(498)
|
||||
Reference in New Issue
Block a user