mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 08:28:12 +01:00
Add ESP32 variant config validator function (#3088)
* Add esp32_variant config validator function * Drop unused is_esp32c3 function Co-authored-by: Otto Winter <otto@otto-winter.com>
This commit is contained in:
parent
ad2f857e15
commit
125c693e3f
1 changed files with 20 additions and 2 deletions
|
@ -65,8 +65,26 @@ def get_esp32_variant():
|
|||
return CORE.data[KEY_ESP32][KEY_VARIANT]
|
||||
|
||||
|
||||
def is_esp32c3():
|
||||
return get_esp32_variant() == VARIANT_ESP32C3
|
||||
def only_on_variant(*, supported=None, unsupported=None):
|
||||
"""Config validator for features only available on some ESP32 variants."""
|
||||
if supported is not None and not isinstance(supported, list):
|
||||
supported = [supported]
|
||||
if unsupported is not None and not isinstance(unsupported, list):
|
||||
unsupported = [unsupported]
|
||||
|
||||
def validator_(obj):
|
||||
variant = get_esp32_variant()
|
||||
if supported is not None and variant not in supported:
|
||||
raise cv.Invalid(
|
||||
f"This feature is only available on {', '.join(supported)}"
|
||||
)
|
||||
if unsupported is not None and variant in unsupported:
|
||||
raise cv.Invalid(
|
||||
f"This feature is not available on {', '.join(unsupported)}"
|
||||
)
|
||||
return obj
|
||||
|
||||
return validator_
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
Loading…
Reference in a new issue