mirror of
https://github.com/esphome/esphome.git
synced 2026-08-23 06:36:23 +00:00
63 lines
2.5 KiB
Python
63 lines
2.5 KiB
Python
"""The three platform-gate branches: BLE-less platforms are rejected with the
|
|
real reason, hub platforms reject GATT-only options by name, and the
|
|
advertisement-only arm applies its own defaults."""
|
|
|
|
import pytest
|
|
|
|
from esphome import config_validation as cv
|
|
from esphome.components import bluetooth_connection, bluetooth_proxy
|
|
from esphome.const import CONF_ACTIVE, KEY_TARGET_PLATFORM
|
|
from esphome.core import CORE, KEY_CORE
|
|
|
|
|
|
def _set_platform(platform: str | None) -> None:
|
|
CORE.data.setdefault(KEY_CORE, {})[KEY_TARGET_PLATFORM] = platform
|
|
|
|
|
|
def test_ble_less_platform_gets_the_real_reason() -> None:
|
|
_set_platform("esp8266")
|
|
with pytest.raises(cv.Invalid, match="not supported on esp8266"):
|
|
bluetooth_proxy.CONFIG_SCHEMA({})
|
|
|
|
|
|
def test_ble_less_platform_connection_keys_fall_through() -> None:
|
|
# The key-level rejection must not fire here — it would imply an
|
|
# advertisement-only proxy exists on this platform.
|
|
_set_platform("esp8266")
|
|
with pytest.raises(cv.Invalid, match="not supported on esp8266"):
|
|
bluetooth_proxy.CONFIG_SCHEMA({"connection_slots": 2})
|
|
|
|
|
|
def test_hub_platform_rejects_active() -> None:
|
|
_set_platform("ln882x")
|
|
with pytest.raises(cv.Invalid, match="Active connections are not supported"):
|
|
bluetooth_proxy.CONFIG_SCHEMA({"active": True})
|
|
|
|
|
|
def test_hub_platform_rejects_connection_keys_by_name() -> None:
|
|
_set_platform("ln882x")
|
|
with pytest.raises(cv.Invalid, match="'connection_slots' requires active"):
|
|
bluetooth_proxy.CONFIG_SCHEMA({"connection_slots": 2})
|
|
with pytest.raises(cv.Invalid, match="'cache_services' requires active"):
|
|
bluetooth_proxy.CONFIG_SCHEMA({"cache_services": True})
|
|
|
|
|
|
def test_hub_platform_accepts_the_advertisement_only_shape() -> None:
|
|
_set_platform("ln882x")
|
|
validated = bluetooth_proxy.CONFIG_SCHEMA({})
|
|
assert validated[CONF_ACTIVE] is False
|
|
|
|
|
|
def test_bluetooth_connection_auto_load_covers_its_includes() -> None:
|
|
# The esp32 connection header includes esp32_ble_client; the auto load
|
|
# must satisfy that closure itself (regression: it once relied on the
|
|
# consumer's auto loads).
|
|
_set_platform("esp32")
|
|
assert "esp32_ble_client" in bluetooth_connection.AUTO_LOAD()
|
|
_set_platform("rp2")
|
|
assert bluetooth_connection.AUTO_LOAD() == ["ble_device_base"]
|
|
# No target platform (tooling resolving the manifest): the union, so
|
|
# dependency closures stay complete for build_codeowners and friends.
|
|
_set_platform(None)
|
|
assert bluetooth_connection.AUTO_LOAD() == ["ble_device_base", "esp32_ble_client"]
|