mirror of
https://github.com/esphome/esphome.git
synced 2025-09-06 05:12:21 +01:00
Allow framework version validator to be maximum version (#3197)
This commit is contained in:
@@ -1713,30 +1713,49 @@ def require_framework_version(
|
||||
esp_idf=None,
|
||||
esp32_arduino=None,
|
||||
esp8266_arduino=None,
|
||||
max_version=False,
|
||||
extra_message=None,
|
||||
):
|
||||
def validator(value):
|
||||
core_data = CORE.data[KEY_CORE]
|
||||
framework = core_data[KEY_TARGET_FRAMEWORK]
|
||||
if framework == "esp-idf":
|
||||
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
|
||||
elif CORE.is_esp32 and framework == "arduino":
|
||||
if esp32_arduino is None:
|
||||
raise Invalid(
|
||||
"This feature is incompatible with ESP32 using arduino framework"
|
||||
)
|
||||
msg = "This feature is incompatible with ESP32 using arduino framework"
|
||||
if extra_message:
|
||||
msg += f". {extra_message}"
|
||||
raise Invalid(msg)
|
||||
required = esp32_arduino
|
||||
elif CORE.is_esp8266 and framework == "arduino":
|
||||
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
|
||||
else:
|
||||
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:
|
||||
raise Invalid(
|
||||
f"This feature requires at least framework version {required}"
|
||||
)
|
||||
msg = f"This feature requires at least framework version {required}"
|
||||
if extra_message:
|
||||
msg += f". {extra_message}"
|
||||
raise Invalid(msg)
|
||||
return value
|
||||
|
||||
return validator
|
||||
|
Reference in New Issue
Block a user