1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-06 05:12:21 +01:00

Check lambdas for return statement (#539)

This commit is contained in:
Otto Winter
2019-05-10 22:13:17 +02:00
committed by GitHub
parent 9dd9e523ed
commit 953d7f6193
15 changed files with 30 additions and 16 deletions

View File

@@ -333,7 +333,7 @@ def templatable(other_validators):
def validator(value):
if isinstance(value, Lambda):
return lambda_(value)
return returning_lambda(value)
if isinstance(other_validators, dict):
return schema(value)
return schema(value)
@@ -974,6 +974,20 @@ def lambda_(value):
return value
def returning_lambda(value):
"""Coerce this configuration option to a lambda.
Additionally, make sure the lambda returns something.
"""
value = lambda_(value)
if u'return' not in value.value:
raise Invalid("Lambda doesn't contain a 'return' statement, but the lambda "
"is expected to return a value. \n"
"Please make sure the lambda contains at least one "
"return statement.")
return value
def dimensions(value):
if isinstance(value, list):
if len(value) != 2: