mirror of
https://github.com/esphome/esphome.git
synced 2026-09-30 16:30:22 +00:00
[wifi][rp2040] Add stable wifi-capability helpers for device-builder (#16300)
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
"""Tests for RP2040 component public helpers."""
|
||||
|
||||
from esphome.components.rp2040 import board_id_has_wifi
|
||||
|
||||
|
||||
def test_board_id_has_wifi_for_known_wifi_board() -> None:
|
||||
"""``rpipicow`` is the canonical Pico W → True."""
|
||||
assert board_id_has_wifi("rpipicow") is True
|
||||
|
||||
|
||||
def test_board_id_has_wifi_for_known_non_wifi_board() -> None:
|
||||
"""Plain ``rpipico`` has no CYW43 → False."""
|
||||
assert board_id_has_wifi("rpipico") is False
|
||||
|
||||
|
||||
def test_board_id_has_wifi_for_rp2350_w_variant() -> None:
|
||||
"""``rpipico2w`` is the RP2350 Pico 2 W → True."""
|
||||
assert board_id_has_wifi("rpipico2w") is True
|
||||
|
||||
|
||||
def test_board_id_has_wifi_for_unknown_board_returns_true() -> None:
|
||||
"""Unknown ids fail open so a custom board is not rejected.
|
||||
|
||||
The validator falls back to ESPHome's compile-time check; the
|
||||
helper returning True here means the wizard emits a ``wifi:``
|
||||
block and any genuinely-unsupported config trips the existing
|
||||
"no CYW43" guard at compile time.
|
||||
"""
|
||||
assert board_id_has_wifi("not-a-real-board-id") is True
|
||||
@@ -0,0 +1,96 @@
|
||||
"""Tests for WiFi component public helpers."""
|
||||
|
||||
import pytest
|
||||
|
||||
from esphome.components.esp32 import const
|
||||
from esphome.components.wifi import has_native_wifi, variant_has_wifi
|
||||
from esphome.const import Platform
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"variant",
|
||||
[
|
||||
const.VARIANT_ESP32,
|
||||
const.VARIANT_ESP32S2,
|
||||
const.VARIANT_ESP32S3,
|
||||
const.VARIANT_ESP32C3,
|
||||
const.VARIANT_ESP32C6,
|
||||
],
|
||||
)
|
||||
def test_variant_has_wifi_for_native_phy_variants(variant: str) -> None:
|
||||
"""Variants with a native WiFi PHY → True."""
|
||||
assert variant_has_wifi(variant) is True
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"variant",
|
||||
[
|
||||
const.VARIANT_ESP32H2,
|
||||
const.VARIANT_ESP32P4,
|
||||
],
|
||||
)
|
||||
def test_variant_has_wifi_for_no_phy_variants(variant: str) -> None:
|
||||
"""Variants that need ``esp32_hosted`` → False."""
|
||||
assert variant_has_wifi(variant) is False
|
||||
|
||||
|
||||
def test_has_native_wifi_dispatches_esp32_to_variant_check() -> None:
|
||||
"""ESP32 platform routes through ``variant_has_wifi``."""
|
||||
assert (
|
||||
has_native_wifi(platform=Platform.ESP32, variant=const.VARIANT_ESP32C3) is True
|
||||
)
|
||||
assert (
|
||||
has_native_wifi(platform=Platform.ESP32, variant=const.VARIANT_ESP32H2) is False
|
||||
)
|
||||
|
||||
|
||||
def test_has_native_wifi_dispatches_rp2040_to_board_check() -> None:
|
||||
"""RP2040 platform routes through ``rp2040.board_id_has_wifi``."""
|
||||
assert has_native_wifi(platform=Platform.RP2040, board="rpipicow") is True
|
||||
assert has_native_wifi(platform=Platform.RP2040, board="rpipico") is False
|
||||
|
||||
|
||||
def test_has_native_wifi_returns_false_for_nrf52() -> None:
|
||||
"""nRF52 family is BLE-only — no Wi-Fi PHY in the platform."""
|
||||
assert has_native_wifi(platform=Platform.NRF52) is False
|
||||
|
||||
|
||||
def test_has_native_wifi_returns_false_for_host() -> None:
|
||||
"""``host`` platform compiles ESPHome to a host binary — no radio at all."""
|
||||
assert has_native_wifi(platform=Platform.HOST) is False
|
||||
|
||||
|
||||
def test_has_native_wifi_returns_false_for_unknown_platform() -> None:
|
||||
"""Unknown platform string fails closed.
|
||||
|
||||
A future platform added to ESPHome that's missed here returns
|
||||
False rather than silently emitting a ``wifi:`` block external
|
||||
tooling would have to compile and reject — fail-closed surfaces
|
||||
the gap as an obvious "needs wifi support added" signal.
|
||||
"""
|
||||
assert has_native_wifi(platform="not-a-real-platform") is False
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"platform",
|
||||
[
|
||||
Platform.ESP8266,
|
||||
Platform.BK72XX,
|
||||
Platform.RTL87XX,
|
||||
Platform.LN882X,
|
||||
Platform.LIBRETINY_OLDSTYLE,
|
||||
],
|
||||
)
|
||||
def test_has_native_wifi_returns_true_for_wifi_first_platforms(platform: str) -> None:
|
||||
"""Catch-all Wi-Fi-first platforms → True regardless of board / variant."""
|
||||
assert has_native_wifi(platform=platform) is True
|
||||
|
||||
|
||||
def test_has_native_wifi_esp32_without_variant_assumes_wifi() -> None:
|
||||
"""ESP32 without a variant id falls open to True (the chip family default)."""
|
||||
assert has_native_wifi(platform=Platform.ESP32) is True
|
||||
|
||||
|
||||
def test_has_native_wifi_rp2040_without_board_assumes_wifi() -> None:
|
||||
"""RP2040 without a board id falls open to True (custom-board default)."""
|
||||
assert has_native_wifi(platform=Platform.RP2040) is True
|
||||
Reference in New Issue
Block a user