diff --git a/esphome/components/bluetooth_proxy/__init__.py b/esphome/components/bluetooth_proxy/__init__.py index ec1df6a06c..4087255410 100644 --- a/esphome/components/bluetooth_proxy/__init__.py +++ b/esphome/components/bluetooth_proxy/__init__.py @@ -1,14 +1,20 @@ +import logging + import esphome.codegen as cg from esphome.components import esp32_ble, esp32_ble_client, esp32_ble_tracker 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"] CODEOWNERS = ["@jesserockz"] +_LOGGER = logging.getLogger(__name__) + CONF_CONNECTION_SLOTS = "connection_slots" CONF_CACHE_SERVICES = "cache_services" CONF_CONNECTIONS = "connections" @@ -41,6 +47,27 @@ def validate_connections(config): esp32_ble_tracker.consume_connection_slots(connection_slots, "bluetooth_proxy")( 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)],