diff --git a/esphome/core/config.py b/esphome/core/config.py index 3d57c5af1d..b1b234adde 100644 --- a/esphome/core/config.py +++ b/esphome/core/config.py @@ -595,11 +595,16 @@ 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 in NATIVE_ARDUINO_PIO_OPTIONS and CORE.using_toolchain_arduino: + elif ( + key in NATIVE_ARDUINO_PIO_OPTIONS + and CORE.using_toolchain_arduino + and vals + ): # The esp8266 native generator reads these as scalars; the # schema also permits the list form, where the last value - # wins like a later platformio.ini line. Other native - # toolchains have no equivalent and fall through to the warning. + # wins like a later platformio.ini line (an empty list falls + # through to the ignored-option warning). Other native + # toolchains have no equivalent and fall through too. cg.add_platformio_option(key, vals[-1]) elif key != "upload_speed": # upload_speed needs no handling: it is read from the raw diff --git a/tests/unit_tests/core/test_config.py b/tests/unit_tests/core/test_config.py index 5bbfb89ee1..e620f8ec7f 100644 --- a/tests/unit_tests/core/test_config.py +++ b/tests/unit_tests/core/test_config.py @@ -1423,6 +1423,10 @@ async def test_add_platformio_options_native_arduino( assert ( "esphome->platformio_options->board_build.filesystem is ignored" in caplog.text ) + # An empty list for an honored key is not a scalar; it falls through + # to the ignored-option warning instead of an IndexError + await config._add_platformio_options({"board_build.ldscript": []}) + assert "board_build.ldscript is ignored" in caplog.text assert "'arduino' toolchain" in caplog.text assert "upload_speed" not in caplog.text