mirror of
https://github.com/esphome/esphome.git
synced 2026-08-22 22:26:21 +00:00
[esp32_ble] Migrate the BLE count machinery to the shared slot counter factory (#18059)
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
esphome:
|
||||
name: slotcount-esp32-proxy
|
||||
|
||||
esp32:
|
||||
board: esp32dev
|
||||
framework:
|
||||
type: esp-idf
|
||||
|
||||
wifi:
|
||||
ssid: MySSID
|
||||
password: password1
|
||||
|
||||
api:
|
||||
|
||||
bluetooth_proxy:
|
||||
active: true
|
||||
@@ -0,0 +1,9 @@
|
||||
esphome:
|
||||
name: slotcount-esp32-tracker
|
||||
|
||||
esp32:
|
||||
board: esp32dev
|
||||
framework:
|
||||
type: esp-idf
|
||||
|
||||
esp32_ble_tracker:
|
||||
@@ -81,3 +81,55 @@ def test_neutral_listener_count_emitted_when_requested() -> None:
|
||||
)
|
||||
CORE.flush_tasks()
|
||||
assert get_define_value(ble_device_base.LISTENER_COUNT_DEFINE) == "1"
|
||||
|
||||
|
||||
def test_esp32_tracker_handler_counts(
|
||||
generate_main: Callable[[str | Path], str],
|
||||
component_config_path: Callable[[str], Path],
|
||||
) -> None:
|
||||
"""A bare tracker registers its four esp32_ble handlers and nothing else."""
|
||||
generate_main(component_config_path("esp32_tracker_only.yaml"))
|
||||
assert get_define_value("ESPHOME_ESP32_BLE_GAP_EVENT_HANDLER_COUNT") == "1"
|
||||
assert get_define_value("ESPHOME_ESP32_BLE_GAP_SCAN_EVENT_HANDLER_COUNT") == "1"
|
||||
assert get_define_value("ESPHOME_ESP32_BLE_GATTC_EVENT_HANDLER_COUNT") == "1"
|
||||
assert get_define_value("ESPHOME_ESP32_BLE_BLE_STATUS_EVENT_HANDLER_COUNT") == "1"
|
||||
assert get_define_value("ESPHOME_ESP32_BLE_GATTS_EVENT_HANDLER_COUNT") is None
|
||||
# No consumer subscribed to scanner state, so the storage compiles out.
|
||||
assert (
|
||||
get_define_value("ESPHOME_ESP32_BLE_TRACKER_SCANNER_STATE_LISTENER_COUNT")
|
||||
is None
|
||||
)
|
||||
assert get_define_value("ESPHOME_ESP32_BLE_TRACKER_LISTENER_COUNT") is None
|
||||
assert get_define_value("ESPHOME_ESP32_BLE_TRACKER_CLIENT_COUNT") is None
|
||||
|
||||
|
||||
def test_esp32_bluetooth_proxy_requests_scanner_state_slot(
|
||||
generate_main: Callable[[str | Path], str],
|
||||
component_config_path: Callable[[str], Path],
|
||||
) -> None:
|
||||
"""The proxy requests one scanner state slot, one raw listener slot and a
|
||||
client slot per connection (three by default with active: true)."""
|
||||
generate_main(component_config_path("esp32_bluetooth_proxy.yaml"))
|
||||
assert (
|
||||
get_define_value("ESPHOME_ESP32_BLE_TRACKER_SCANNER_STATE_LISTENER_COUNT")
|
||||
== "1"
|
||||
)
|
||||
assert get_define_value("ESPHOME_ESP32_BLE_TRACKER_LISTENER_COUNT") == "1"
|
||||
assert get_define_value("ESPHOME_ESP32_BLE_TRACKER_CLIENT_COUNT") == "3"
|
||||
|
||||
|
||||
def test_counts_reset_between_compiles(
|
||||
generate_main: Callable[[str | Path], str],
|
||||
component_config_path: Callable[[str], Path],
|
||||
) -> None:
|
||||
"""A second compile in the same process starts from zero.
|
||||
|
||||
The module level counters this change removes leaked across compiles in a
|
||||
long lived host process (dashboard, device-builder), growing the handler
|
||||
counts by one per compile and oversizing the StaticCallbackManager storage.
|
||||
"""
|
||||
generate_main(component_config_path("esp32_tracker_only.yaml"))
|
||||
assert get_define_value("ESPHOME_ESP32_BLE_GAP_EVENT_HANDLER_COUNT") == "1"
|
||||
CORE.reset()
|
||||
generate_main(component_config_path("esp32_tracker_only.yaml"))
|
||||
assert get_define_value("ESPHOME_ESP32_BLE_GAP_EVENT_HANDLER_COUNT") == "1"
|
||||
|
||||
Reference in New Issue
Block a user