Template lambda is optional

This commit is contained in:
Otto Winter 2019-02-16 13:12:49 +01:00
parent ef7b936d60
commit fcef3be5c7
No known key found for this signature in database
GPG key ID: DB66C0BE6013F97E
3 changed files with 18 additions and 15 deletions

View file

@ -16,7 +16,7 @@ BinarySensorPublishAction = binary_sensor.binary_sensor_ns.class_('BinarySensorP
PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend({ PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend({
cv.GenerateID(): cv.declare_variable_id(TemplateBinarySensor), cv.GenerateID(): cv.declare_variable_id(TemplateBinarySensor),
vol.Required(CONF_LAMBDA): cv.lambda_, vol.Optional(CONF_LAMBDA): cv.lambda_,
}).extend(cv.COMPONENT_SCHEMA.schema)) }).extend(cv.COMPONENT_SCHEMA.schema))
@ -26,6 +26,7 @@ def to_code(config):
binary_sensor.setup_binary_sensor(var, config) binary_sensor.setup_binary_sensor(var, config)
setup_component(var, config) setup_component(var, config)
if CONF_LAMBDA in config:
for template_ in process_lambda(config[CONF_LAMBDA], [], for template_ in process_lambda(config[CONF_LAMBDA], [],
return_type=optional.template(bool_)): return_type=optional.template(bool_)):
yield yield

View file

@ -13,7 +13,7 @@ SensorPublishAction = sensor.sensor_ns.class_('SensorPublishAction', Action)
PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({ PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({
cv.GenerateID(): cv.declare_variable_id(TemplateSensor), 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, vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval,
}).extend(cv.COMPONENT_SCHEMA.schema)) }).extend(cv.COMPONENT_SCHEMA.schema))
@ -25,6 +25,7 @@ def to_code(config):
sensor.setup_sensor(template, config) sensor.setup_sensor(template, config)
setup_component(template, config) setup_component(template, config)
if CONF_LAMBDA in config:
for template_ in process_lambda(config[CONF_LAMBDA], [], for template_ in process_lambda(config[CONF_LAMBDA], [],
return_type=optional.template(float_)): return_type=optional.template(float_)):
yield yield

View file

@ -12,7 +12,7 @@ TemplateTextSensor = text_sensor.text_sensor_ns.class_('TemplateTextSensor',
PLATFORM_SCHEMA = cv.nameable(text_sensor.TEXT_SENSOR_PLATFORM_SCHEMA.extend({ PLATFORM_SCHEMA = cv.nameable(text_sensor.TEXT_SENSOR_PLATFORM_SCHEMA.extend({
cv.GenerateID(): cv.declare_variable_id(TemplateTextSensor), 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, vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval,
}).extend(cv.COMPONENT_SCHEMA.schema)) }).extend(cv.COMPONENT_SCHEMA.schema))
@ -23,6 +23,7 @@ def to_code(config):
text_sensor.setup_text_sensor(template, config) text_sensor.setup_text_sensor(template, config)
setup_component(template, config) setup_component(template, config)
if CONF_LAMBDA in config:
for template_ in process_lambda(config[CONF_LAMBDA], [], for template_ in process_lambda(config[CONF_LAMBDA], [],
return_type=optional.template(std_string)): return_type=optional.template(std_string)):
yield yield