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:
Oxan van Leeuwen 2022-02-19 11:41:34 +01:00 committed by GitHub
parent ad2f857e15
commit 125c693e3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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