From f8226cd481dfcd5d6e296edb43827a47b128d065 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 23 Sep 2025 19:42:46 -0500 Subject: [PATCH] [esp32_ble] Remove Arduino-specific BLE limitations and SplitDefaults (#10780) --- .../components/bluetooth_proxy/__init__.py | 30 ++----------------- esphome/components/esp32_ble/__init__.py | 10 ++----- .../components/esp32_ble_tracker/__init__.py | 13 +++----- 3 files changed, 10 insertions(+), 43 deletions(-) diff --git a/esphome/components/bluetooth_proxy/__init__.py b/esphome/components/bluetooth_proxy/__init__.py index f21b5028c7..42a88f1421 100644 --- a/esphome/components/bluetooth_proxy/__init__.py +++ b/esphome/components/bluetooth_proxy/__init__.py @@ -6,8 +6,6 @@ from esphome.components.esp32 import add_idf_sdkconfig_option from esphome.components.esp32_ble import BTLoggers import esphome.config_validation as cv from esphome.const import CONF_ACTIVE, CONF_ID -from esphome.core import CORE -from esphome.log import AnsiFore, color AUTO_LOAD = ["esp32_ble_client", "esp32_ble_tracker"] DEPENDENCIES = ["api", "esp32"] @@ -48,26 +46,6 @@ def validate_connections(config): config ) - # Warn about connection slot waste when using Arduino framework - if CORE.using_arduino and connection_slots: - _LOGGER.warning( - "Bluetooth Proxy with active connections on Arduino framework has suboptimal performance.\n" - "If BLE connections fail, they can waste connection slots for 10 seconds because\n" - "Arduino doesn't allow configuring the BLE connection timeout (fixed at 30s).\n" - "ESP-IDF framework allows setting it to 20s to match client timeouts.\n" - "\n" - "To switch to ESP-IDF, add this to your YAML:\n" - " esp32:\n" - " framework:\n" - " type: esp-idf\n" - "\n" - "For detailed migration instructions, see:\n" - "%s", - color( - AnsiFore.BLUE, "https://esphome.io/guides/esp32_arduino_to_idf.html" - ), - ) - return { **config, CONF_CONNECTIONS: [CONNECTION_SCHEMA({}) for _ in range(connection_slots)], @@ -81,19 +59,17 @@ CONFIG_SCHEMA = cv.All( { cv.GenerateID(): cv.declare_id(BluetoothProxy), cv.Optional(CONF_ACTIVE, default=True): cv.boolean, - cv.SplitDefault(CONF_CACHE_SERVICES, esp32_idf=True): cv.All( - cv.only_with_esp_idf, cv.boolean - ), + cv.Optional(CONF_CACHE_SERVICES, default=True): cv.boolean, cv.Optional( CONF_CONNECTION_SLOTS, default=DEFAULT_CONNECTION_SLOTS, ): cv.All( cv.positive_int, - cv.Range(min=1, max=esp32_ble_tracker.max_connections()), + cv.Range(min=1, max=esp32_ble_tracker.IDF_MAX_CONNECTIONS), ), cv.Optional(CONF_CONNECTIONS): cv.All( cv.ensure_list(CONNECTION_SCHEMA), - cv.Length(min=1, max=esp32_ble_tracker.max_connections()), + cv.Length(min=1, max=esp32_ble_tracker.IDF_MAX_CONNECTIONS), ), } ) diff --git a/esphome/components/esp32_ble/__init__.py b/esphome/components/esp32_ble/__init__.py index 8886dc415b..dae9799028 100644 --- a/esphome/components/esp32_ble/__init__.py +++ b/esphome/components/esp32_ble/__init__.py @@ -174,16 +174,12 @@ CONFIG_SCHEMA = cv.Schema( cv.Optional( CONF_ADVERTISING_CYCLE_TIME, default="10s" ): cv.positive_time_period_milliseconds, - cv.SplitDefault(CONF_DISABLE_BT_LOGS, esp32_idf=True): cv.All( - cv.only_with_esp_idf, cv.boolean - ), - cv.SplitDefault(CONF_CONNECTION_TIMEOUT, esp32_idf="20s"): cv.All( - cv.only_with_esp_idf, + cv.Optional(CONF_DISABLE_BT_LOGS, default=True): cv.boolean, + cv.Optional(CONF_CONNECTION_TIMEOUT, default="20s"): cv.All( cv.positive_time_period_seconds, cv.Range(min=TimePeriod(seconds=10), max=TimePeriod(seconds=180)), ), - cv.SplitDefault(CONF_MAX_NOTIFICATIONS, esp32_idf=12): cv.All( - cv.only_with_esp_idf, + cv.Optional(CONF_MAX_NOTIFICATIONS, default=12): cv.All( cv.positive_int, cv.Range(min=1, max=64), ), diff --git a/esphome/components/esp32_ble_tracker/__init__.py b/esphome/components/esp32_ble_tracker/__init__.py index 8655d5a02a..787fb9fb65 100644 --- a/esphome/components/esp32_ble_tracker/__init__.py +++ b/esphome/components/esp32_ble_tracker/__init__.py @@ -150,10 +150,6 @@ def as_reversed_hex_array(value): ) -def max_connections() -> int: - return IDF_MAX_CONNECTIONS if CORE.using_esp_idf else DEFAULT_MAX_CONNECTIONS - - def consume_connection_slots( value: int, consumer: str ) -> Callable[[MutableMapping], MutableMapping]: @@ -172,7 +168,7 @@ CONFIG_SCHEMA = cv.All( cv.GenerateID(): cv.declare_id(ESP32BLETracker), cv.GenerateID(esp32_ble.CONF_BLE_ID): cv.use_id(esp32_ble.ESP32BLE), cv.Optional(CONF_MAX_CONNECTIONS, default=DEFAULT_MAX_CONNECTIONS): cv.All( - cv.positive_int, cv.Range(min=0, max=max_connections()) + cv.positive_int, cv.Range(min=0, max=IDF_MAX_CONNECTIONS) ), cv.Optional(CONF_SCAN_PARAMETERS, default={}): cv.All( cv.Schema( @@ -238,9 +234,8 @@ def validate_remaining_connections(config): if used_slots <= config[CONF_MAX_CONNECTIONS]: return config slot_users = ", ".join(slots) - hard_limit = max_connections() - if used_slots < hard_limit: + if used_slots < IDF_MAX_CONNECTIONS: _LOGGER.warning( "esp32_ble_tracker exceeded `%s`: components attempted to consume %d " "connection slot(s) out of available configured maximum %d connection " @@ -262,9 +257,9 @@ def validate_remaining_connections(config): f"out of available configured maximum {config[CONF_MAX_CONNECTIONS]} " f"connection slot(s); Decrease the number of BLE clients ({slot_users})" ) - if config[CONF_MAX_CONNECTIONS] < hard_limit: + if config[CONF_MAX_CONNECTIONS] < IDF_MAX_CONNECTIONS: msg += f" or increase {CONF_MAX_CONNECTIONS}` to {used_slots}" - msg += f" to stay under the {hard_limit} connection slot(s) limit." + msg += f" to stay under the {IDF_MAX_CONNECTIONS} connection slot(s) limit." raise cv.Invalid(msg)