From a13a1225b7201c71d0db5b4dc921e00c5dcc07e5 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Tue, 15 Feb 2022 11:57:47 +1300 Subject: [PATCH] Allow framework version validator to be maximum version (#3197) --- esphome/components/fastled_clockless/light.py | 7 +++- esphome/components/fastled_spi/light.py | 7 +++- esphome/config_validation.py | 35 ++++++++++++++----- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/esphome/components/fastled_clockless/light.py b/esphome/components/fastled_clockless/light.py index acf9488ae3..dc456d4959 100644 --- a/esphome/components/fastled_clockless/light.py +++ b/esphome/components/fastled_clockless/light.py @@ -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", + ), ) diff --git a/esphome/components/fastled_spi/light.py b/esphome/components/fastled_spi/light.py index a729fc015a..b3ce1722ee 100644 --- a/esphome/components/fastled_spi/light.py +++ b/esphome/components/fastled_spi/light.py @@ -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", + ), ) diff --git a/esphome/config_validation.py b/esphome/config_validation.py index 2e7a4e5677..8e1c63a54e 100644 --- a/esphome/config_validation.py +++ b/esphome/config_validation.py @@ -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