Address review: slot-cap testing mode, derived source filter, breadcrumbs

- Skip the hub-platform GATT slot cap in testing mode (mirrors
  esp32_ble.validate_connection_slots) so grouped builds validate
- Derive the neutral engine's source filter from the backend registry so
  a new platform cannot validate and then fail at link
- Log the real code on refused service discovery and cancelled connects;
  read completions get the same breadcrumb writes have
- Comment accuracy: the dumper arm is the legacy shape, not a superset
- Ledger tests: real-validator end-to-end path and the testing-mode skip
This commit is contained in:
J. Nick Koston
2026-08-09 09:42:50 -05:00
parent 8924640593
commit f6158597ac
4 changed files with 68 additions and 11 deletions
@@ -3,15 +3,55 @@
import pytest
from esphome import config_validation as cv
from esphome.components import bluetooth_connection
from esphome.const import KEY_CORE, KEY_TARGET_PLATFORM, PLATFORM_RP2
from esphome.components import (
ble_client,
ble_device_base,
bluetooth_connection,
bluetooth_proxy,
)
from esphome.const import (
CONF_MAC_ADDRESS,
KEY_CORE,
KEY_TARGET_PLATFORM,
PLATFORM_RP2,
PlatformFramework,
)
from esphome.core import CORE
from ..types import SetCoreConfigCallable
def test_gatt_slot_ledger_rejects_overcommit_on_rp2() -> None:
# The cross-component cap must reject two claims on rp2.
# The cap logic in isolation: two hand charges must trip it.
CORE.data.setdefault(KEY_CORE, {})[KEY_TARGET_PLATFORM] = PLATFORM_RP2
bluetooth_connection.consume_gatt_slot("bluetooth_proxy")({})
bluetooth_connection.consume_gatt_slot("ble_client")({})
with pytest.raises(cv.Invalid, match="supports at most 1 GATT client"):
bluetooth_connection.FINAL_VALIDATE_SCHEMA({})
def test_gatt_slot_ledger_skipped_in_testing_mode() -> None:
# Grouped component builds merge fixtures past the cap; the check defers
# to testing mode like esp32_ble.validate_connection_slots.
CORE.data.setdefault(KEY_CORE, {})[KEY_TARGET_PLATFORM] = PLATFORM_RP2
bluetooth_connection.consume_gatt_slot("bluetooth_proxy")({})
bluetooth_connection.consume_gatt_slot("ble_client")({})
CORE.testing_mode = True
try:
bluetooth_connection.FINAL_VALIDATE_SCHEMA({})
finally:
CORE.testing_mode = False
def test_real_validators_charge_the_ledger_on_rp2(
set_core_config: SetCoreConfigCallable,
) -> None:
# End to end through the component CONFIG_SCHEMAs (no hand charges):
# removing either consumer's consume_gatt_slot call fails this test.
set_core_config(PlatformFramework.RP2_ARDUINO)
ble_device_base.register_hub_provider("rp2_ble_tracker")
CORE.loaded_integrations.add("rp2_ble_tracker")
bluetooth_proxy.CONFIG_SCHEMA({})
ble_client.CONFIG_SCHEMA({CONF_MAC_ADDRESS: "AA:BB:CC:DD:EE:FF"})
with pytest.raises(cv.Invalid, match="requested by: bluetooth_proxy, ble_client"):
bluetooth_connection.FINAL_VALIDATE_SCHEMA({})