From 7fb18f395f447d427516994332ba23e73393da93 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 21 Aug 2026 20:25:23 -0500 Subject: [PATCH] Honor board_build.f_cpu under the native ESP8266 Arduino toolchain Dropping it was a real regression: many published ESP8266 configs pin board_build.f_cpu: 160000000L for timing-sensitive integrations (MHI-AC-Ctrl documents the 160 MHz requirement in its example), and the warn-and-drop left those devices at 80 MHz. The option now routes into CORE.platformio_options under toolchain: arduino for the generator to consume; other native toolchains keep the warning. --- esphome/core/config.py | 7 +++++++ tests/unit_tests/core/test_config.py | 11 ++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/esphome/core/config.py b/esphome/core/config.py index 1c481894b2..71f2ebfc94 100644 --- a/esphome/core/config.py +++ b/esphome/core/config.py @@ -593,6 +593,13 @@ async def _add_platformio_options(pio_options: dict[str, str | list[str]]) -> No # platformio/library.py); filters top-level libraries and # discovered dependencies cg.add_platformio_option(key, vals) + elif key == "board_build.f_cpu" and CORE.using_toolchain_arduino: + # A real-world overclock knob (many published ESP8266 configs + # pin 160000000L for timing-sensitive integrations); the + # esp8266 native generator reads it for -DF_CPU. Other native + # toolchains have no equivalent and fall through to the + # warning. + cg.add_platformio_option(key, val) elif key != "upload_speed": # upload_speed needs no handling: it is read from the raw # config at upload time (upload_using_esptool) diff --git a/tests/unit_tests/core/test_config.py b/tests/unit_tests/core/test_config.py index f322c1d4c9..0a143c466c 100644 --- a/tests/unit_tests/core/test_config.py +++ b/tests/unit_tests/core/test_config.py @@ -1397,8 +1397,8 @@ def test_esphome_build_internals_are_yaml_only() -> None: async def test_add_platformio_options_native_arduino( caplog: pytest.LogCaptureFixture, ) -> None: - """The native ESP8266 Arduino toolchain warns about ignored options the - same way the native IDF toolchain does.""" + """The native ESP8266 Arduino toolchain honors board_build.f_cpu (a + real-world overclock knob) and warns about the rest like native IDF.""" CORE.toolchain = Toolchain.ARDUINO CORE.data[KEY_CORE] = { KEY_TARGET_PLATFORM: "esp8266", @@ -1408,11 +1408,16 @@ async def test_add_platformio_options_native_arduino( await config._add_platformio_options( { "board_build.f_cpu": "160000000L", + "board_build.filesystem": "littlefs", "upload_speed": "115200", } ) - assert "esphome->platformio_options->board_build.f_cpu is ignored" in caplog.text + assert CORE.platformio_options["board_build.f_cpu"] == "160000000L" + assert "board_build.f_cpu is ignored" not in caplog.text + assert ( + "esphome->platformio_options->board_build.filesystem is ignored" in caplog.text + ) assert "'arduino' toolchain" in caplog.text assert "upload_speed" not in caplog.text