Allow framework version validator to be maximum version (#3197)

This commit is contained in:
Jesse Hills 2022-02-15 11:57:47 +13:00
parent dd554bcdf4
commit dcc80f9032
No known key found for this signature in database
GPG key ID: BEAAE804EFD8E83A
3 changed files with 39 additions and 10 deletions

View file

@ -49,7 +49,12 @@ CONFIG_SCHEMA = cv.All(
} }
), ),
_validate, _validate,
cv.only_with_arduino, cv.require_framework_version(
esp8266_arduino=cv.Version(2, 7, 4),
esp32_arduino=cv.Version(99, 0, 0),
max_version=True,
extra_message="Please see note on documentation for FastLED",
),
) )

View file

@ -33,7 +33,12 @@ CONFIG_SCHEMA = cv.All(
cv.Optional(CONF_DATA_RATE): cv.frequency, cv.Optional(CONF_DATA_RATE): cv.frequency,
} }
), ),
cv.only_with_arduino, cv.require_framework_version(
esp8266_arduino=cv.Version(2, 7, 4),
esp32_arduino=cv.Version(99, 0, 0),
max_version=True,
extra_message="Please see note on documentation for FastLED",
),
) )

View file

@ -1713,30 +1713,49 @@ def require_framework_version(
esp_idf=None, esp_idf=None,
esp32_arduino=None, esp32_arduino=None,
esp8266_arduino=None, esp8266_arduino=None,
max_version=False,
extra_message=None,
): ):
def validator(value): def validator(value):
core_data = CORE.data[KEY_CORE] core_data = CORE.data[KEY_CORE]
framework = core_data[KEY_TARGET_FRAMEWORK] framework = core_data[KEY_TARGET_FRAMEWORK]
if framework == "esp-idf": if framework == "esp-idf":
if esp_idf is None: if esp_idf is None:
raise Invalid("This feature is incompatible with esp-idf") msg = "This feature is incompatible with esp-idf"
if extra_message:
msg += f". {extra_message}"
raise Invalid(msg)
required = esp_idf required = esp_idf
elif CORE.is_esp32 and framework == "arduino": elif CORE.is_esp32 and framework == "arduino":
if esp32_arduino is None: if esp32_arduino is None:
raise Invalid( msg = "This feature is incompatible with ESP32 using arduino framework"
"This feature is incompatible with ESP32 using arduino framework" if extra_message:
) msg += f". {extra_message}"
raise Invalid(msg)
required = esp32_arduino required = esp32_arduino
elif CORE.is_esp8266 and framework == "arduino": elif CORE.is_esp8266 and framework == "arduino":
if esp8266_arduino is None: if esp8266_arduino is None:
raise Invalid("This feature is incompatible with ESP8266") msg = "This feature is incompatible with ESP8266"
if extra_message:
msg += f". {extra_message}"
raise Invalid(msg)
required = esp8266_arduino required = esp8266_arduino
else: else:
raise NotImplementedError raise NotImplementedError
if max_version:
if core_data[KEY_FRAMEWORK_VERSION] > required:
msg = f"This feature requires framework version {required} or lower"
if extra_message:
msg += f". {extra_message}"
raise Invalid(msg)
return value
if core_data[KEY_FRAMEWORK_VERSION] < required: if core_data[KEY_FRAMEWORK_VERSION] < required:
raise Invalid( msg = f"This feature requires at least framework version {required}"
f"This feature requires at least framework version {required}" if extra_message:
) msg += f". {extra_message}"
raise Invalid(msg)
return value return value
return validator return validator