[esp32] Improve flexibility of `only_on_variant` (#9390)

This commit is contained in:
Jesse Hills 2025-07-09 10:51:17 +12:00 committed by GitHub
parent 4158a5c2a3
commit 5c8b330eaa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -189,7 +189,7 @@ def get_download_types(storage_json):
] ]
def only_on_variant(*, supported=None, unsupported=None): def only_on_variant(*, supported=None, unsupported=None, msg_prefix="This feature"):
"""Config validator for features only available on some ESP32 variants.""" """Config validator for features only available on some ESP32 variants."""
if supported is not None and not isinstance(supported, list): if supported is not None and not isinstance(supported, list):
supported = [supported] supported = [supported]
@ -200,11 +200,11 @@ def only_on_variant(*, supported=None, unsupported=None):
variant = get_esp32_variant() variant = get_esp32_variant()
if supported is not None and variant not in supported: if supported is not None and variant not in supported:
raise cv.Invalid( raise cv.Invalid(
f"This feature is only available on {', '.join(supported)}" f"{msg_prefix} is only available on {', '.join(supported)}"
) )
if unsupported is not None and variant in unsupported: if unsupported is not None and variant in unsupported:
raise cv.Invalid( raise cv.Invalid(
f"This feature is not available on {', '.join(unsupported)}" f"{msg_prefix} is not available on {', '.join(unsupported)}"
) )
return obj return obj