From fcef3be5c791a4c667e5667ad3513983d08aaa14 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Sat, 16 Feb 2019 13:12:49 +0100 Subject: [PATCH] Template lambda is optional --- esphome/components/binary_sensor/template.py | 11 ++++++----- esphome/components/sensor/template.py | 11 ++++++----- esphome/components/text_sensor/template.py | 11 ++++++----- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/esphome/components/binary_sensor/template.py b/esphome/components/binary_sensor/template.py index e0952a4061..a02709626d 100644 --- a/esphome/components/binary_sensor/template.py +++ b/esphome/components/binary_sensor/template.py @@ -16,7 +16,7 @@ BinarySensorPublishAction = binary_sensor.binary_sensor_ns.class_('BinarySensorP PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(TemplateBinarySensor), - vol.Required(CONF_LAMBDA): cv.lambda_, + vol.Optional(CONF_LAMBDA): cv.lambda_, }).extend(cv.COMPONENT_SCHEMA.schema)) @@ -26,10 +26,11 @@ def to_code(config): binary_sensor.setup_binary_sensor(var, config) setup_component(var, config) - for template_ in process_lambda(config[CONF_LAMBDA], [], - return_type=optional.template(bool_)): - yield - add(var.set_template(template_)) + if CONF_LAMBDA in config: + for template_ in process_lambda(config[CONF_LAMBDA], [], + return_type=optional.template(bool_)): + yield + add(var.set_template(template_)) BUILD_FLAGS = '-DUSE_TEMPLATE_BINARY_SENSOR' diff --git a/esphome/components/sensor/template.py b/esphome/components/sensor/template.py index fb28f06dc8..7182ae672e 100644 --- a/esphome/components/sensor/template.py +++ b/esphome/components/sensor/template.py @@ -13,7 +13,7 @@ SensorPublishAction = sensor.sensor_ns.class_('SensorPublishAction', Action) PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(TemplateSensor), - vol.Required(CONF_LAMBDA): cv.lambda_, + vol.Optional(CONF_LAMBDA): cv.lambda_, vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval, }).extend(cv.COMPONENT_SCHEMA.schema)) @@ -25,10 +25,11 @@ def to_code(config): sensor.setup_sensor(template, config) setup_component(template, config) - for template_ in process_lambda(config[CONF_LAMBDA], [], - return_type=optional.template(float_)): - yield - add(template.set_template(template_)) + if CONF_LAMBDA in config: + for template_ in process_lambda(config[CONF_LAMBDA], [], + return_type=optional.template(float_)): + yield + add(template.set_template(template_)) BUILD_FLAGS = '-DUSE_TEMPLATE_SENSOR' diff --git a/esphome/components/text_sensor/template.py b/esphome/components/text_sensor/template.py index aeae550b23..ff00014f8e 100644 --- a/esphome/components/text_sensor/template.py +++ b/esphome/components/text_sensor/template.py @@ -12,7 +12,7 @@ TemplateTextSensor = text_sensor.text_sensor_ns.class_('TemplateTextSensor', PLATFORM_SCHEMA = cv.nameable(text_sensor.TEXT_SENSOR_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(TemplateTextSensor), - vol.Required(CONF_LAMBDA): cv.lambda_, + vol.Optional(CONF_LAMBDA): cv.lambda_, vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval, }).extend(cv.COMPONENT_SCHEMA.schema)) @@ -23,10 +23,11 @@ def to_code(config): text_sensor.setup_text_sensor(template, config) setup_component(template, config) - for template_ in process_lambda(config[CONF_LAMBDA], [], - return_type=optional.template(std_string)): - yield - add(template.set_template(template_)) + if CONF_LAMBDA in config: + for template_ in process_lambda(config[CONF_LAMBDA], [], + return_type=optional.template(std_string)): + yield + add(template.set_template(template_)) BUILD_FLAGS = '-DUSE_TEMPLATE_TEXT_SENSOR'