Add support for complex template structures to data_template (#3255)

This commit is contained in:
Pascal Vizeli 2016-09-08 18:19:47 +02:00 committed by Johann Kellerman
parent 94e3986d54
commit 267cda447e
4 changed files with 55 additions and 5 deletions

View file

@ -244,6 +244,20 @@ def template(value):
raise vol.Invalid('invalid template ({})'.format(ex))
def template_complex(value):
"""Validate a complex jinja2 template."""
if isinstance(value, list):
for idx, element in enumerate(value):
value[idx] = template_complex(element)
return value
if isinstance(value, dict):
for key, element in value.items():
value[key] = template_complex(element)
return value
return template(value)
def time(value):
"""Validate time."""
time_val = dt_util.parse_time(value)
@ -310,7 +324,7 @@ SERVICE_SCHEMA = vol.All(vol.Schema({
vol.Exclusive('service', 'service name'): service,
vol.Exclusive('service_template', 'service name'): template,
vol.Optional('data'): dict,
vol.Optional('data_template'): {match_all: template},
vol.Optional('data_template'): {match_all: template_complex},
vol.Optional(CONF_ENTITY_ID): entity_ids,
}), has_at_least_one_key('service', 'service_template'))