mirror of
https://github.com/esphome/esphome.git
synced 2025-09-26 15:12:21 +01:00
[esp32_ble] Remove Arduino-specific BLE limitations and SplitDefaults (#10780)
This commit is contained in:
@@ -6,8 +6,6 @@ from esphome.components.esp32 import add_idf_sdkconfig_option
|
|||||||
from esphome.components.esp32_ble import BTLoggers
|
from esphome.components.esp32_ble import BTLoggers
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome.const import CONF_ACTIVE, CONF_ID
|
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"]
|
AUTO_LOAD = ["esp32_ble_client", "esp32_ble_tracker"]
|
||||||
DEPENDENCIES = ["api", "esp32"]
|
DEPENDENCIES = ["api", "esp32"]
|
||||||
@@ -48,26 +46,6 @@ def validate_connections(config):
|
|||||||
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 {
|
return {
|
||||||
**config,
|
**config,
|
||||||
CONF_CONNECTIONS: [CONNECTION_SCHEMA({}) for _ in range(connection_slots)],
|
CONF_CONNECTIONS: [CONNECTION_SCHEMA({}) for _ in range(connection_slots)],
|
||||||
@@ -81,19 +59,17 @@ CONFIG_SCHEMA = cv.All(
|
|||||||
{
|
{
|
||||||
cv.GenerateID(): cv.declare_id(BluetoothProxy),
|
cv.GenerateID(): cv.declare_id(BluetoothProxy),
|
||||||
cv.Optional(CONF_ACTIVE, default=True): cv.boolean,
|
cv.Optional(CONF_ACTIVE, default=True): cv.boolean,
|
||||||
cv.SplitDefault(CONF_CACHE_SERVICES, esp32_idf=True): cv.All(
|
cv.Optional(CONF_CACHE_SERVICES, default=True): cv.boolean,
|
||||||
cv.only_with_esp_idf, cv.boolean
|
|
||||||
),
|
|
||||||
cv.Optional(
|
cv.Optional(
|
||||||
CONF_CONNECTION_SLOTS,
|
CONF_CONNECTION_SLOTS,
|
||||||
default=DEFAULT_CONNECTION_SLOTS,
|
default=DEFAULT_CONNECTION_SLOTS,
|
||||||
): cv.All(
|
): cv.All(
|
||||||
cv.positive_int,
|
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.Optional(CONF_CONNECTIONS): cv.All(
|
||||||
cv.ensure_list(CONNECTION_SCHEMA),
|
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),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@@ -174,16 +174,12 @@ CONFIG_SCHEMA = cv.Schema(
|
|||||||
cv.Optional(
|
cv.Optional(
|
||||||
CONF_ADVERTISING_CYCLE_TIME, default="10s"
|
CONF_ADVERTISING_CYCLE_TIME, default="10s"
|
||||||
): cv.positive_time_period_milliseconds,
|
): cv.positive_time_period_milliseconds,
|
||||||
cv.SplitDefault(CONF_DISABLE_BT_LOGS, esp32_idf=True): cv.All(
|
cv.Optional(CONF_DISABLE_BT_LOGS, default=True): cv.boolean,
|
||||||
cv.only_with_esp_idf, cv.boolean
|
cv.Optional(CONF_CONNECTION_TIMEOUT, default="20s"): cv.All(
|
||||||
),
|
|
||||||
cv.SplitDefault(CONF_CONNECTION_TIMEOUT, esp32_idf="20s"): cv.All(
|
|
||||||
cv.only_with_esp_idf,
|
|
||||||
cv.positive_time_period_seconds,
|
cv.positive_time_period_seconds,
|
||||||
cv.Range(min=TimePeriod(seconds=10), max=TimePeriod(seconds=180)),
|
cv.Range(min=TimePeriod(seconds=10), max=TimePeriod(seconds=180)),
|
||||||
),
|
),
|
||||||
cv.SplitDefault(CONF_MAX_NOTIFICATIONS, esp32_idf=12): cv.All(
|
cv.Optional(CONF_MAX_NOTIFICATIONS, default=12): cv.All(
|
||||||
cv.only_with_esp_idf,
|
|
||||||
cv.positive_int,
|
cv.positive_int,
|
||||||
cv.Range(min=1, max=64),
|
cv.Range(min=1, max=64),
|
||||||
),
|
),
|
||||||
|
@@ -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(
|
def consume_connection_slots(
|
||||||
value: int, consumer: str
|
value: int, consumer: str
|
||||||
) -> Callable[[MutableMapping], MutableMapping]:
|
) -> Callable[[MutableMapping], MutableMapping]:
|
||||||
@@ -172,7 +168,7 @@ CONFIG_SCHEMA = cv.All(
|
|||||||
cv.GenerateID(): cv.declare_id(ESP32BLETracker),
|
cv.GenerateID(): cv.declare_id(ESP32BLETracker),
|
||||||
cv.GenerateID(esp32_ble.CONF_BLE_ID): cv.use_id(esp32_ble.ESP32BLE),
|
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.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.Optional(CONF_SCAN_PARAMETERS, default={}): cv.All(
|
||||||
cv.Schema(
|
cv.Schema(
|
||||||
@@ -238,9 +234,8 @@ def validate_remaining_connections(config):
|
|||||||
if used_slots <= config[CONF_MAX_CONNECTIONS]:
|
if used_slots <= config[CONF_MAX_CONNECTIONS]:
|
||||||
return config
|
return config
|
||||||
slot_users = ", ".join(slots)
|
slot_users = ", ".join(slots)
|
||||||
hard_limit = max_connections()
|
|
||||||
|
|
||||||
if used_slots < hard_limit:
|
if used_slots < IDF_MAX_CONNECTIONS:
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"esp32_ble_tracker exceeded `%s`: components attempted to consume %d "
|
"esp32_ble_tracker exceeded `%s`: components attempted to consume %d "
|
||||||
"connection slot(s) out of available configured maximum %d connection "
|
"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"out of available configured maximum {config[CONF_MAX_CONNECTIONS]} "
|
||||||
f"connection slot(s); Decrease the number of BLE clients ({slot_users})"
|
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" 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)
|
raise cv.Invalid(msg)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user