mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 09:17:46 +01:00
Allow framework version validator to be maximum version (#3197)
This commit is contained in:
parent
0ec84be5da
commit
a13a1225b7
3 changed files with 39 additions and 10 deletions
|
@ -49,7 +49,12 @@ CONFIG_SCHEMA = cv.All(
|
|||
}
|
||||
),
|
||||
_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",
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -33,7 +33,12 @@ CONFIG_SCHEMA = cv.All(
|
|||
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",
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue