diff --git a/esphome/components/network/__init__.py b/esphome/components/network/__init__.py index 29dced46c6..96a6f11b9a 100644 --- a/esphome/components/network/__init__.py +++ b/esphome/components/network/__init__.py @@ -32,7 +32,8 @@ CONF_TCP_SEND_BUFFER = "tcp_send_buffer" # stock ESP-IDF default (5744 bytes) stalls bursty senders like a Bluetooth # proxy streaming GATT notifications. Bounds follow the lwIP guidance for the # default 1440 byte MSS: at least 2 x MSS, at most 65535 without window -# scaling. +# scaling. The cap is kept even when window scaling is on (high performance +# with PSRAM) as a deliberate conservative bound. TCP_SEND_BUFFER_MIN = 2880 TCP_SEND_BUFFER_MAX = 65535 @@ -463,6 +464,11 @@ async def to_code(config): # After the high performance block so an explicit size wins over the # bundle's 65534 (last write wins in the sdkconfig store). if (tcp_send_buffer := config.get(CONF_TCP_SEND_BUFFER)) is not None: + if CORE.is_esp32 and should_enable: + _LOGGER.info( + "TCP send buffer set to %d bytes by configuration (overriding high performance value)", + tcp_send_buffer, + ) add_idf_sdkconfig_option("CONFIG_LWIP_TCP_SND_BUF_DEFAULT", tcp_send_buffer) if CORE.is_nrf52: diff --git a/tests/component_tests/network/test_tcp_send_buffer.py b/tests/component_tests/network/test_tcp_send_buffer.py index e193030fca..6498921243 100644 --- a/tests/component_tests/network/test_tcp_send_buffer.py +++ b/tests/component_tests/network/test_tcp_send_buffer.py @@ -14,16 +14,23 @@ import pytest from voluptuous import Invalid from esphome import config_validation as cv -from esphome.components.esp32.const import KEY_VARIANT, VARIANT_ESP32 -from esphome.components.network import CONFIG_SCHEMA -from esphome.const import KEY_FRAMEWORK_VERSION, PlatformFramework +from esphome.components.esp32.const import ( + KEY_SDKCONFIG_OPTIONS, + KEY_VARIANT, + VARIANT_ESP32, +) +from esphome.components.network import ( + CONF_TCP_SEND_BUFFER, + CONFIG_SCHEMA, + TCP_SEND_BUFFER_MAX, + TCP_SEND_BUFFER_MIN, +) +from esphome.const import KEY_ESP32, KEY_FRAMEWORK_VERSION, PlatformFramework from esphome.core import CORE from tests.component_tests.types import SetCoreConfigCallable def _sdkconfig_option(name: str) -> int | None: - from esphome.components.esp32.const import KEY_ESP32, KEY_SDKCONFIG_OPTIONS - return CORE.data[KEY_ESP32][KEY_SDKCONFIG_OPTIONS].get(name) @@ -44,6 +51,18 @@ def test_tcp_send_buffer_overrides_high_performance( assert _sdkconfig_option("CONFIG_LWIP_TCP_SND_BUF_DEFAULT") == 16384 +@pytest.mark.parametrize("value", [TCP_SEND_BUFFER_MIN, TCP_SEND_BUFFER_MAX]) +def test_boundary_values_accepted( + set_core_config: SetCoreConfigCallable, value: int +) -> None: + set_core_config( + PlatformFramework.ESP32_IDF, + core_data={KEY_FRAMEWORK_VERSION: cv.Version(5, 5, 5)}, + platform_data={KEY_VARIANT: VARIANT_ESP32}, + ) + assert CONFIG_SCHEMA({"tcp_send_buffer": value})[CONF_TCP_SEND_BUFFER] == value + + @pytest.mark.parametrize("value", ["1kB", "128kB"]) def test_out_of_range_rejected( set_core_config: SetCoreConfigCallable, value: str diff --git a/tests/components/network/test-tcp-send-buffer.esp32-idf.yaml b/tests/components/network/test-tcp-send-buffer.esp32-idf.yaml deleted file mode 100644 index b83b60a68e..0000000000 --- a/tests/components/network/test-tcp-send-buffer.esp32-idf.yaml +++ /dev/null @@ -1,6 +0,0 @@ -wifi: - ssid: MySSID - password: password1 - -network: - tcp_send_buffer: 32kB diff --git a/tests/components/network/test.esp32-idf.yaml b/tests/components/network/test.esp32-idf.yaml index 7c01bafa0d..6ad365ead2 100644 --- a/tests/components/network/test.esp32-idf.yaml +++ b/tests/components/network/test.esp32-idf.yaml @@ -2,3 +2,4 @@ network: enable_high_performance: true + tcp_send_buffer: 32kB