[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
+64 -17
View File
@@ -94,7 +94,7 @@ from esphome.const import (
PLATFORM_BK72XX,
PLATFORM_ESP32,
PLATFORM_ESP8266,
PLATFORM_RP2040,
PLATFORM_RP2,
Toolchain,
)
from esphome.core import CORE, EsphomeError
@@ -1226,7 +1226,7 @@ def test_choose_upload_log_host_no_defaults_with_rp2040_bootsel(
mock_choose_prompt: Mock,
) -> None:
"""Test interactive mode shows RP2040 BOOTSEL option via picotool."""
setup_core(platform=PLATFORM_RP2040)
setup_core(platform=PLATFORM_RP2)
with (
patch(
@@ -1249,7 +1249,7 @@ def test_choose_upload_log_host_no_defaults_with_rp2040_bootsel(
@pytest.mark.usefixtures("mock_no_serial_ports")
def test_choose_upload_log_host_rp2040_no_device_shows_bootsel_help() -> None:
"""Test BOOTSEL instructions shown when no RP2040 device found."""
setup_core(platform=PLATFORM_RP2040)
setup_core(platform=PLATFORM_RP2)
with (
patch(
@@ -1271,7 +1271,7 @@ def test_choose_upload_log_host_rp2040_bootsel_tip_with_ota(
) -> None:
"""Test BOOTSEL tip shown when only OTA options exist for RP2040."""
setup_core(
platform=PLATFORM_RP2040,
platform=PLATFORM_RP2,
config={CONF_OTA: [{CONF_PLATFORM: CONF_ESPHOME}]},
address="192.168.1.100",
)
@@ -1300,7 +1300,7 @@ def test_choose_upload_log_host_rp2040_bootsel_tip_with_serial_ports(
mock_choose_prompt: Mock,
) -> None:
"""Test BOOTSEL tip shown when serial ports exist but no BOOTSEL device."""
setup_core(platform=PLATFORM_RP2040)
setup_core(platform=PLATFORM_RP2)
mock_ports = [MockSerialPort("/dev/ttyACM0", "RP2040 Serial")]
with (
@@ -1325,7 +1325,7 @@ def test_choose_upload_log_host_rp2040_permission_error_no_options(
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test permission warning shown when BOOTSEL device found but not accessible."""
setup_core(platform=PLATFORM_RP2040)
setup_core(platform=PLATFORM_RP2)
with (
patch(
@@ -1355,7 +1355,7 @@ def test_choose_upload_log_host_rp2040_permission_error_with_ota(
) -> None:
"""Test permission warning shown with OTA fallback available."""
setup_core(
platform=PLATFORM_RP2040,
platform=PLATFORM_RP2,
config={CONF_OTA: [{CONF_PLATFORM: CONF_ESPHOME}]},
address="192.168.1.100",
)
@@ -1412,7 +1412,7 @@ def test_choose_upload_log_host_rp2040_serial_and_bootsel(
mock_choose_prompt: Mock,
) -> None:
"""Test both serial ports and BOOTSEL option shown for RP2040."""
setup_core(platform=PLATFORM_RP2040)
setup_core(platform=PLATFORM_RP2)
mock_ports = [MockSerialPort("/dev/ttyACM0", "RP2040 Serial")]
with (
@@ -1665,7 +1665,7 @@ def test_upload_using_esptool_with_file_path(
@pytest.mark.parametrize(
"platform,device",
[
(PLATFORM_RP2040, "/dev/ttyACM0"),
(PLATFORM_RP2, "/dev/ttyACM0"),
(PLATFORM_BK72XX, "/dev/ttyUSB0"), # LibreTiny platform
],
)
@@ -1720,7 +1720,7 @@ def test_upload_using_platformio_creates_signed_bin_for_rp2040(
tmp_path: Path,
) -> None:
"""Test that upload_using_platformio creates firmware.bin.signed for RP2040."""
setup_core(platform=PLATFORM_RP2040)
setup_core(platform=PLATFORM_RP2)
build_dir = tmp_path / "build"
build_dir.mkdir()
@@ -1756,6 +1756,53 @@ def test_upload_using_platformio_skips_signed_bin_for_non_rp2040(
assert result == 0
def test_upload_using_platformio_skips_signed_bin_when_already_present(
tmp_path: Path,
) -> None:
"""The signed-bin copy is idempotent: if ``firmware.bin.signed`` already
exists on the RP2 build path, the upload step must not overwrite it
(and must not fail when the unsigned ``firmware.bin`` is absent)."""
setup_core(platform=PLATFORM_RP2)
build_dir = tmp_path / "build"
build_dir.mkdir()
# Pre-existing signed bin with distinct content — must be preserved.
signed_bin = build_dir / "firmware.bin.signed"
signed_bin.write_bytes(b"already signed")
# No unsigned firmware.bin on disk — the `is_file()` guard must hold.
firmware_elf = build_dir / "firmware.elf"
firmware_elf.write_bytes(b"elf")
mock_idedata = MagicMock()
mock_idedata.firmware_elf_path = str(firmware_elf)
with (
patch("esphome.platformio.toolchain.get_idedata", return_value=mock_idedata),
patch("esphome.platformio.toolchain.run_platformio_cli_run", return_value=0),
):
result = upload_using_platformio({}, "/dev/ttyACM0")
assert result == 0
# Pre-existing signed bin is untouched.
assert signed_bin.read_bytes() == b"already signed"
def test_upload_using_platformio_handles_port_none(tmp_path: Path) -> None:
"""The upload step must work without a serial port (PlatformIO picks the
target itself); the ``--upload-port`` flag is only appended when a port
is provided."""
setup_core(platform=PLATFORM_ESP32)
with patch(
"esphome.platformio.toolchain.run_platformio_cli_run", return_value=0
) as mock_run:
result = upload_using_platformio({}, None)
assert result == 0
args = mock_run.call_args.args
assert "--upload-port" not in args
def test_upload_program_serial_upload_failed(
mock_upload_using_esptool: Mock,
mock_get_port_type: Mock,
@@ -1783,7 +1830,7 @@ def test_upload_program_bootsel(
mock_get_port_type: Mock,
) -> None:
"""Test upload_program with BOOTSEL for RP2040."""
setup_core(platform=PLATFORM_RP2040)
setup_core(platform=PLATFORM_RP2)
mock_get_port_type.return_value = "BOOTSEL"
mock_upload_using_picotool.return_value = 0
@@ -1804,7 +1851,7 @@ def test_upload_program_bootsel_failed(
mock_get_port_type: Mock,
) -> None:
"""Test upload_program when BOOTSEL upload fails."""
setup_core(platform=PLATFORM_RP2040)
setup_core(platform=PLATFORM_RP2)
mock_get_port_type.return_value = "BOOTSEL"
mock_upload_using_picotool.return_value = 1
@@ -1821,7 +1868,7 @@ def test_upload_program_bootsel_failed(
def test_upload_using_picotool_success(tmp_path: Path) -> None:
"""Test upload_using_picotool succeeds."""
setup_core(platform=PLATFORM_RP2040, tmp_path=tmp_path)
setup_core(platform=PLATFORM_RP2, tmp_path=tmp_path)
build_dir = tmp_path / "build"
build_dir.mkdir()
@@ -1858,7 +1905,7 @@ def test_upload_using_picotool_success(tmp_path: Path) -> None:
def test_upload_using_picotool_no_elf(tmp_path: Path) -> None:
"""Test upload_using_picotool when ELF file is missing."""
setup_core(platform=PLATFORM_RP2040, tmp_path=tmp_path)
setup_core(platform=PLATFORM_RP2, tmp_path=tmp_path)
build_dir = tmp_path / "build"
build_dir.mkdir()
@@ -1876,7 +1923,7 @@ def test_upload_using_picotool_no_elf(tmp_path: Path) -> None:
def test_upload_using_picotool_not_found(tmp_path: Path) -> None:
"""Test upload_using_picotool when picotool binary not found."""
setup_core(platform=PLATFORM_RP2040, tmp_path=tmp_path)
setup_core(platform=PLATFORM_RP2, tmp_path=tmp_path)
build_dir = tmp_path / "build"
build_dir.mkdir()
@@ -1896,7 +1943,7 @@ def test_upload_using_picotool_not_found(tmp_path: Path) -> None:
def test_upload_using_picotool_permission_error(tmp_path: Path) -> None:
"""Test upload_using_picotool shows helpful message on permission error."""
setup_core(platform=PLATFORM_RP2040, tmp_path=tmp_path)
setup_core(platform=PLATFORM_RP2, tmp_path=tmp_path)
build_dir = tmp_path / "build"
build_dir.mkdir()
@@ -6411,7 +6458,7 @@ def test_command_run_rp2040_bootsel_redetects_serial_port() -> None:
picks up the newly enumerated serial port before showing logs."""
setup_core(
config={"logger": {}, CONF_API: {}, CONF_MDNS: {CONF_DISABLED: False}},
platform=PLATFORM_RP2040,
platform=PLATFORM_RP2,
)
args = MockArgs()