From c9f6b9e3749042af747738e893609ad0389ebb23 Mon Sep 17 00:00:00 2001 From: jota29 Date: Wed, 15 Mar 2023 15:56:36 +0000 Subject: [PATCH] fiexd check of required config only for esp32 platform --- esphome/components/optolink/__init__.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/esphome/components/optolink/__init__.py b/esphome/components/optolink/__init__.py index 2f89bdd262..49630e804b 100644 --- a/esphome/components/optolink/__init__.py +++ b/esphome/components/optolink/__init__.py @@ -32,16 +32,15 @@ DeviceInfoSensor = optolink_ns.class_( DEVICE_INFO_SENSOR_ID = "device_info_sensor_id" -def validate_required_rx_on_esp32(config): - if CORE.is_esp32 and CONF_RX_PIN not in config: - raise cv.Invalid(f"{CONF_RX_PIN} required on esp32 platform") - return config +def required_on_esp32(attribute): + """Validate that this option can only be specified on the given target platforms.""" + def validator_(config): + if CORE.is_esp32 and attribute not in config: + raise cv.Invalid(f"{attribute} is required on esp32") + return config -def validate_required_tx_on_esp32(config): - if CORE.is_esp32 and CONF_TX_PIN not in config: - raise cv.Invalid(f"{CONF_TX_PIN} required on esp32 platform") - return config + return validator_ CONFIG_SCHEMA = cv.All( @@ -66,7 +65,8 @@ CONFIG_SCHEMA = cv.All( ).extend(cv.COMPONENT_SCHEMA), cv.only_with_arduino, cv.only_on(["esp32", "esp8266"]), - cv.ensure_list(validate_required_rx_on_esp32, validate_required_tx_on_esp32), + required_on_esp32(CONF_RX_PIN), + required_on_esp32(CONF_TX_PIN), )