diff --git a/esphome/components/esp32/__init__.py b/esphome/components/esp32/__init__.py index 50d6d229f9..8ae6262f2f 100644 --- a/esphome/components/esp32/__init__.py +++ b/esphome/components/esp32/__init__.py @@ -316,17 +316,26 @@ def _parse_platform_version(value): def _detect_variant(value): - if CONF_VARIANT not in value: - board = value[CONF_BOARD] - if board not in BOARDS: + board = value[CONF_BOARD] + if board in BOARDS: + variant = BOARDS[board][KEY_VARIANT] + if CONF_VARIANT in value and variant != value[CONF_VARIANT]: raise cv.Invalid( - "This board is unknown, please set the variant manually", + f"Option '{CONF_VARIANT}' does not match selected board.", + path=[CONF_VARIANT], + ) + value = value.copy() + value[CONF_VARIANT] = variant + else: + if CONF_VARIANT not in value: + raise cv.Invalid( + "This board is unknown, if you are sure you want to compile with this board selection, " + f"override with option '{CONF_VARIANT}'", path=[CONF_BOARD], ) - - value = value.copy() - value[CONF_VARIANT] = BOARDS[board][KEY_VARIANT] - + _LOGGER.warning( + "This board is unknown. Make sure the chosen chip component is correct.", + ) return value diff --git a/esphome/components/libretiny/__init__.py b/esphome/components/libretiny/__init__.py index 34aff0ae16..a8034f8fab 100644 --- a/esphome/components/libretiny/__init__.py +++ b/esphome/components/libretiny/__init__.py @@ -1,6 +1,10 @@ import json import logging -from os.path import dirname, isfile, join +from os.path import ( + dirname, + isfile, + join, +) import esphome.codegen as cg import esphome.config_validation as cv @@ -55,15 +59,25 @@ def _detect_variant(value): component: LibreTinyComponent = CORE.data[KEY_LIBRETINY][KEY_COMPONENT_DATA] board = value[CONF_BOARD] # read board-default family if not specified - if CONF_FAMILY not in value: - if board not in component.boards: + if board not in component.boards: + if CONF_FAMILY not in value: raise cv.Invalid( - "This board is unknown, please set the family manually. " - "Also, make sure the chosen chip component is correct.", + "This board is unknown, if you are sure you want to compile with this board selection, " + f"override with option '{CONF_FAMILY}'", path=[CONF_BOARD], ) + _LOGGER.warning( + "This board is unknown. Make sure the chosen chip component is correct.", + ) + else: + family = component.boards[board][KEY_FAMILY] + if CONF_FAMILY in value and family != value[CONF_FAMILY]: + raise cv.Invalid( + f"Option '{CONF_FAMILY}' does not match selected board.", + path=[CONF_FAMILY], + ) value = value.copy() - value[CONF_FAMILY] = component.boards[board][KEY_FAMILY] + value[CONF_FAMILY] = family # read component name matching this family value[CONF_COMPONENT_ID] = FAMILY_COMPONENT[value[CONF_FAMILY]] # make sure the chosen component matches the family @@ -72,11 +86,6 @@ def _detect_variant(value): f"The chosen family doesn't belong to '{component.name}' component. The correct component is '{value[CONF_COMPONENT_ID]}'", path=[CONF_FAMILY], ) - # warn anyway if the board wasn't found - if board not in component.boards: - _LOGGER.warning( - "This board is unknown. Make sure the chosen chip component is correct.", - ) return value