[esp32] Fix crash with empty platformio_options: value (#7920)

This commit is contained in:
Clyde Stubbs 2024-12-06 11:16:59 +11:00 committed by Jesse Hills
parent 86ae1c5931
commit c8ec0bb7ea
No known key found for this signature in database
GPG Key ID: BEAAE804EFD8E83A

View File

@ -355,24 +355,20 @@ def _detect_variant(value):
def final_validate(config): def final_validate(config):
if CONF_PLATFORMIO_OPTIONS not in fv.full_config.get()[CONF_ESPHOME]: if not (
pio_options := fv.full_config.get()[CONF_ESPHOME].get(CONF_PLATFORMIO_OPTIONS)
):
# Not specified or empty
return config return config
pio_flash_size_key = "board_upload.flash_size" pio_flash_size_key = "board_upload.flash_size"
pio_partitions_key = "board_build.partitions" pio_partitions_key = "board_build.partitions"
if ( if CONF_PARTITIONS in config and pio_partitions_key in pio_options:
CONF_PARTITIONS in config
and pio_partitions_key
in fv.full_config.get()[CONF_ESPHOME][CONF_PLATFORMIO_OPTIONS]
):
raise cv.Invalid( raise cv.Invalid(
f"Do not specify '{pio_partitions_key}' in '{CONF_PLATFORMIO_OPTIONS}' with '{CONF_PARTITIONS}' in esp32" f"Do not specify '{pio_partitions_key}' in '{CONF_PLATFORMIO_OPTIONS}' with '{CONF_PARTITIONS}' in esp32"
) )
if ( if pio_flash_size_key in pio_options:
pio_flash_size_key
in fv.full_config.get()[CONF_ESPHOME][CONF_PLATFORMIO_OPTIONS]
):
raise cv.Invalid( raise cv.Invalid(
f"Please specify {CONF_FLASH_SIZE} within esp32 configuration only" f"Please specify {CONF_FLASH_SIZE} within esp32 configuration only"
) )