mirror of
https://github.com/esphome/esphome.git
synced 2026-06-01 01:19:45 +08:00
[wifi] Accept lowercase variant in variant_has_wifi (#16345)
This commit is contained in:
@@ -76,11 +76,17 @@ def variant_has_wifi(variant: str) -> bool:
|
|||||||
Variants without a native PHY (ESP32-H2, ESP32-P4) need the
|
Variants without a native PHY (ESP32-H2, ESP32-P4) need the
|
||||||
``esp32_hosted`` co-processor to use ``wifi:``.
|
``esp32_hosted`` co-processor to use ``wifi:``.
|
||||||
|
|
||||||
|
Case-insensitive on *variant* so external callers can pass either
|
||||||
|
the upstream uppercase form (e.g. ``"ESP32H2"`` from
|
||||||
|
``const.VARIANT_ESP32H2``) or a lowercase form their own enum
|
||||||
|
surfaces (e.g. ``"esp32h2"`` from device-builder's
|
||||||
|
``Esp32Variant``). Both classify identically.
|
||||||
|
|
||||||
Used by device-builder (esphome/device-builder) to decide whether
|
Used by device-builder (esphome/device-builder) to decide whether
|
||||||
its basic-setup wizard emits a ``wifi:`` block — please keep the
|
its basic-setup wizard emits a ``wifi:`` block — please keep the
|
||||||
signature stable.
|
signature stable.
|
||||||
"""
|
"""
|
||||||
return variant not in NO_WIFI_VARIANTS
|
return variant.upper() not in NO_WIFI_VARIANTS
|
||||||
|
|
||||||
|
|
||||||
_WIFI_FIRST_PLATFORMS: frozenset[str] = frozenset(
|
_WIFI_FIRST_PLATFORMS: frozenset[str] = frozenset(
|
||||||
|
|||||||
@@ -10,27 +10,44 @@ from esphome.const import Platform
|
|||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"variant",
|
"variant",
|
||||||
[
|
[
|
||||||
|
# Upstream's canonical uppercase form.
|
||||||
const.VARIANT_ESP32,
|
const.VARIANT_ESP32,
|
||||||
const.VARIANT_ESP32S2,
|
const.VARIANT_ESP32S2,
|
||||||
const.VARIANT_ESP32S3,
|
const.VARIANT_ESP32S3,
|
||||||
const.VARIANT_ESP32C3,
|
const.VARIANT_ESP32C3,
|
||||||
const.VARIANT_ESP32C6,
|
const.VARIANT_ESP32C6,
|
||||||
|
# Lowercase form external callers (e.g. device-builder's
|
||||||
|
# ``Esp32Variant`` StrEnum) surface.
|
||||||
|
"esp32",
|
||||||
|
"esp32s3",
|
||||||
|
"esp32c3",
|
||||||
|
# Mixed-case — defence in depth against future callers that
|
||||||
|
# pull the value off some other serialisation.
|
||||||
|
"Esp32",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_variant_has_wifi_for_native_phy_variants(variant: str) -> None:
|
def test_variant_has_wifi_for_native_phy_variants(variant: str) -> None:
|
||||||
"""Variants with a native WiFi PHY → True."""
|
"""Variants with a native WiFi PHY → True, case-insensitive."""
|
||||||
assert variant_has_wifi(variant) is True
|
assert variant_has_wifi(variant) is True
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"variant",
|
"variant",
|
||||||
[
|
[
|
||||||
|
# Upstream's canonical uppercase form.
|
||||||
const.VARIANT_ESP32H2,
|
const.VARIANT_ESP32H2,
|
||||||
const.VARIANT_ESP32P4,
|
const.VARIANT_ESP32P4,
|
||||||
|
# Lowercase form external callers (e.g. device-builder's
|
||||||
|
# ``Esp32Variant`` StrEnum) surface.
|
||||||
|
"esp32h2",
|
||||||
|
"esp32p4",
|
||||||
|
# Mixed-case — defence in depth against future callers that
|
||||||
|
# pull the value off some other serialisation.
|
||||||
|
"Esp32H2",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_variant_has_wifi_for_no_phy_variants(variant: str) -> None:
|
def test_variant_has_wifi_for_no_phy_variants(variant: str) -> None:
|
||||||
"""Variants that need ``esp32_hosted`` → False."""
|
"""Variants that need ``esp32_hosted`` → False, case-insensitive."""
|
||||||
assert variant_has_wifi(variant) is False
|
assert variant_has_wifi(variant) is False
|
||||||
|
|
||||||
|
|
||||||
@@ -44,6 +61,18 @@ def test_has_native_wifi_dispatches_esp32_to_variant_check() -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_has_native_wifi_esp32_variant_case_insensitive() -> None:
|
||||||
|
"""has_native_wifi accepts lowercase variant input.
|
||||||
|
|
||||||
|
External callers (device-builder's wizard, etc.) may surface
|
||||||
|
variant strings from their own enums that don't match upstream's
|
||||||
|
uppercase convention. The dispatcher should classify them
|
||||||
|
identically.
|
||||||
|
"""
|
||||||
|
assert has_native_wifi(platform=Platform.ESP32, variant="esp32h2") is False
|
||||||
|
assert has_native_wifi(platform=Platform.ESP32, variant="esp32c3") is True
|
||||||
|
|
||||||
|
|
||||||
def test_has_native_wifi_dispatches_rp2040_to_board_check() -> None:
|
def test_has_native_wifi_dispatches_rp2040_to_board_check() -> None:
|
||||||
"""RP2040 platform routes through ``rp2040.board_id_has_wifi``."""
|
"""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="rpipicow") is True
|
||||||
|
|||||||
Reference in New Issue
Block a user