[rp2] Rename rp2040 platform to rp2 (#17145)

Co-authored-by: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com>
This commit is contained in:
Jesse Hills
2026-07-07 08:20:24 +12:00
committed by GitHub
co-authored by Jonathan Swoboda
parent 9caf431740
commit cdd334284e
153 changed files with 1297 additions and 1062 deletions
+196 -8
View File
@@ -39,7 +39,7 @@ from esphome.const import (
PLATFORM_ESP8266,
PLATFORM_HOST,
PLATFORM_LN882X,
PLATFORM_RP2040,
PLATFORM_RP2,
PLATFORM_RTL87XX,
SCHEDULER_DONT_RUN,
TYPE_GIT,
@@ -438,7 +438,7 @@ def hex_int__valid(value):
("esp-idf", PLATFORM_ESP32, VARIANT_ESP32C6, "16", "16", "14", "14"),
("arduino", PLATFORM_ESP32, VARIANT_ESP32H2, "18", "17", "18", "17"),
("esp-idf", PLATFORM_ESP32, VARIANT_ESP32H2, "19", "19", "17", "17"),
("arduino", PLATFORM_RP2040, None, "20", "20", "20", "20"),
("arduino", PLATFORM_RP2, None, "20", "20", "20", "20"),
("arduino", PLATFORM_BK72XX, None, "21", "21", "21", "21"),
("arduino", PLATFORM_RTL87XX, None, "22", "22", "22", "22"),
("arduino", PLATFORM_LN882X, None, "23", "23", "23", "23"),
@@ -469,7 +469,7 @@ def test_split_default(framework, platform, variant, full, idf, arduino, simple)
"esp32_c3": "11",
"esp32_c6": "14",
"esp32_h2": "17",
"rp2040": "20",
"rp2": "20",
"bk72xx": "21",
"rtl87xx": "22",
"ln882x": "23",
@@ -517,7 +517,7 @@ def test_split_default(framework, platform, variant, full, idf, arduino, simple)
("arduino", PLATFORM_ESP32, "ESP32 using arduino framework"),
("esp-idf", PLATFORM_ESP32, "ESP32 using esp-idf framework"),
("arduino", PLATFORM_ESP8266, "ESP8266 using arduino framework"),
("arduino", PLATFORM_RP2040, "RP2040 using arduino framework"),
("arduino", PLATFORM_RP2, "RP2 using arduino framework"),
("arduino", PLATFORM_BK72XX, "BK72XX using arduino framework"),
("host", PLATFORM_HOST, "HOST using host framework"),
],
@@ -540,7 +540,7 @@ def test_require_framework_version(framework, platform, message):
esp_idf=cv.Version(0, 5, 0),
esp32_arduino=cv.Version(0, 5, 0),
esp8266_arduino=cv.Version(0, 5, 0),
rp2040_arduino=cv.Version(0, 5, 0),
rp2_arduino=cv.Version(0, 5, 0),
bk72xx_arduino=cv.Version(0, 5, 0),
host=cv.Version(0, 5, 0),
extra_message="test 1",
@@ -556,7 +556,7 @@ def test_require_framework_version(framework, platform, message):
esp_idf=cv.Version(2, 0, 0),
esp32_arduino=cv.Version(2, 0, 0),
esp8266_arduino=cv.Version(2, 0, 0),
rp2040_arduino=cv.Version(2, 0, 0),
rp2_arduino=cv.Version(2, 0, 0),
bk72xx_arduino=cv.Version(2, 0, 0),
host=cv.Version(2, 0, 0),
extra_message="test 2",
@@ -567,7 +567,7 @@ def test_require_framework_version(framework, platform, message):
esp_idf=cv.Version(1, 5, 0),
esp32_arduino=cv.Version(1, 5, 0),
esp8266_arduino=cv.Version(1, 5, 0),
rp2040_arduino=cv.Version(1, 5, 0),
rp2_arduino=cv.Version(1, 5, 0),
bk72xx_arduino=cv.Version(1, 5, 0),
host=cv.Version(1, 5, 0),
max_version=True,
@@ -584,7 +584,7 @@ def test_require_framework_version(framework, platform, message):
esp_idf=cv.Version(0, 5, 0),
esp32_arduino=cv.Version(0, 5, 0),
esp8266_arduino=cv.Version(0, 5, 0),
rp2040_arduino=cv.Version(0, 5, 0),
rp2_arduino=cv.Version(0, 5, 0),
bk72xx_arduino=cv.Version(0, 5, 0),
host=cv.Version(0, 5, 0),
max_version=True,
@@ -599,6 +599,194 @@ def test_require_framework_version(framework, platform, message):
)("test")
def _setup_core_for_framework(platform: str, framework: str) -> None:
"""Wire CORE.data with the minimum keys for require_framework_version /
SplitDefault to evaluate without raising KeyError."""
from esphome.const import (
KEY_CORE,
KEY_FRAMEWORK_VERSION,
KEY_TARGET_FRAMEWORK,
KEY_TARGET_PLATFORM,
)
CORE.data[KEY_CORE] = {
KEY_TARGET_PLATFORM: platform,
KEY_TARGET_FRAMEWORK: framework,
KEY_FRAMEWORK_VERSION: cv.Version(1, 0, 0),
}
def test_only_on_rp2_passes_on_rp2_platform() -> None:
"""``cv.only_on_rp2`` is the canonical family gate. It accepts any value
untouched when the configured platform is rp2."""
_setup_core_for_framework(PLATFORM_RP2, "arduino")
assert cv.only_on_rp2("anything") == "anything"
def test_only_on_rp2_rejects_other_platforms() -> None:
"""The same gate raises ``Invalid`` outside the rp2 platform."""
_setup_core_for_framework(PLATFORM_ESP32, "arduino")
with pytest.raises(Invalid, match="rp2"):
cv.only_on_rp2("anything")
def test_only_on_rp2040_delegates_and_warns_once(caplog) -> None:
"""``cv.only_on_rp2040`` is a deprecation shim — it logs a one-shot
warning, dedupes via CORE.data, and delegates to ``only_on_rp2``.
Repeated calls in the same run must not log again."""
import logging
_setup_core_for_framework(PLATFORM_RP2, "arduino")
# Reset the dedupe flag so this test is independent of order.
CORE.data.pop(cv._ONLY_ON_RP2040_DEPRECATED_KEY, None)
with caplog.at_level(logging.WARNING, logger="esphome.config_validation"):
assert cv.only_on_rp2040("ok") == "ok"
first_warnings = [r for r in caplog.records if "only_on_rp2040" in r.message]
assert len(first_warnings) == 1
assert "2027.7.0" in first_warnings[0].message
# Second call dedupes — no additional warning is emitted.
assert cv.only_on_rp2040("ok") == "ok"
warnings_after_second = [
r for r in caplog.records if "only_on_rp2040" in r.message
]
assert len(warnings_after_second) == 1
def test_only_on_rp2040_still_gates_on_non_rp2(caplog) -> None:
"""The deprecation shim must still raise on non-rp2 platforms — it
delegates to ``only_on_rp2``, so the gating behavior is preserved."""
import logging
_setup_core_for_framework(PLATFORM_ESP32, "arduino")
CORE.data.pop(cv._ONLY_ON_RP2040_DEPRECATED_KEY, None)
with (
caplog.at_level(logging.WARNING, logger="esphome.config_validation"),
pytest.raises(Invalid, match="rp2"),
):
cv.only_on_rp2040("anything")
def test_require_framework_version_esp32_variant_specific_key() -> None:
"""ESP32 variant-specific kwargs (``esp32_c3_arduino``) must win over
the base ``esp32_arduino`` key when the configured variant matches."""
from esphome.components.esp32 import KEY_ESP32
from esphome.const import (
KEY_CORE,
KEY_FRAMEWORK_VERSION,
KEY_TARGET_FRAMEWORK,
KEY_TARGET_PLATFORM,
KEY_VARIANT,
)
CORE.data[KEY_CORE] = {
KEY_TARGET_PLATFORM: PLATFORM_ESP32,
KEY_TARGET_FRAMEWORK: "arduino",
KEY_FRAMEWORK_VERSION: cv.Version(1, 2, 0),
}
CORE.data[KEY_ESP32] = {KEY_VARIANT: VARIANT_ESP32C3}
# Variant-specific entry permits this version; base key would reject it.
assert (
cv.require_framework_version(
esp32_arduino=cv.Version(5, 0, 0), # would reject
esp32_c3_arduino=cv.Version(1, 0, 0), # wins, ok
)("test")
== "test"
)
def test_require_framework_version_rp2_variant_specific_key() -> None:
"""RP2 variant kwargs (``rp2_2040_arduino``) must win over the base
``rp2_arduino`` key when ``CORE.data['rp2']['variant']`` is wired."""
from esphome.const import (
KEY_CORE,
KEY_FRAMEWORK_VERSION,
KEY_TARGET_FRAMEWORK,
KEY_TARGET_PLATFORM,
)
CORE.data[KEY_CORE] = {
KEY_TARGET_PLATFORM: PLATFORM_RP2,
KEY_TARGET_FRAMEWORK: "arduino",
KEY_FRAMEWORK_VERSION: cv.Version(1, 2, 0),
}
CORE.data["rp2"] = {"variant": "RP2040"}
# Variant key wins — base ``rp2_arduino`` (which would reject) is ignored.
assert (
cv.require_framework_version(
rp2_arduino=cv.Version(5, 0, 0), # would reject
rp2_2040_arduino=cv.Version(1, 0, 0), # wins, ok
)("test")
== "test"
)
# Without a variant kwarg the base ``rp2_arduino`` is used (fallback).
CORE.data["rp2"] = {"variant": "RP2350"}
assert (
cv.require_framework_version(
rp2_arduino=cv.Version(1, 0, 0),
)("test")
== "test"
)
def test_split_default_rp2_variant_keys() -> None:
"""``SplitDefault`` resolves ``rp2_<chip>_<framework>`` first, falling
back to ``rp2_<chip>`` and ``rp2_<framework>`` before the base key."""
from esphome.const import KEY_CORE, KEY_TARGET_FRAMEWORK, KEY_TARGET_PLATFORM
CORE.data[KEY_CORE] = {
KEY_TARGET_PLATFORM: PLATFORM_RP2,
KEY_TARGET_FRAMEWORK: "arduino",
}
CORE.data["rp2"] = {"variant": "RP2040"}
schema = cv.Schema(
{
cv.SplitDefault(
"full",
rp2="base",
rp2_arduino="base-framework",
rp2_2040="variant-only",
rp2_2040_arduino="variant-framework",
): str,
}
)
# Most specific (variant + framework) wins.
assert schema({}).get("full") == "variant-framework"
# Drop the most-specific kwarg → variant-only wins.
schema = cv.Schema(
{
cv.SplitDefault(
"full",
rp2="base",
rp2_arduino="base-framework",
rp2_2040="variant-only",
): str,
}
)
assert schema({}).get("full") == "variant-only"
# RP2350 variant — no rp2_2350_* kwargs → fall through to base framework.
CORE.data["rp2"] = {"variant": "RP2350"}
schema = cv.Schema(
{
cv.SplitDefault(
"full",
rp2="base",
rp2_arduino="base-framework",
rp2_2040="not-this",
): str,
}
)
assert schema({}).get("full") == "base-framework"
def test_only_with_single_component_loaded() -> None:
"""Test OnlyWith with single component when component is loaded."""
CORE.loaded_integrations = {"mqtt"}