Pre-compile templates (#3515)

* Pre-compile templates

* Compile templates in numeric_state condition
This commit is contained in:
Paulus Schoutsen 2016-09-25 13:33:01 -07:00 committed by GitHub
parent b3d67a7ed9
commit 0c0feda834
15 changed files with 134 additions and 80 deletions

View file

@ -37,6 +37,11 @@ PLATFORM_SCHEMA = mqtt.MQTT_RO_PLATFORM_SCHEMA.extend({
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the MQTT binary sensor."""
value_template = config.get(CONF_VALUE_TEMPLATE)
if value_template is not None:
value_template = template.compile_template(hass, value_template)
add_devices([MqttBinarySensor(
hass,
config.get(CONF_NAME),
@ -45,7 +50,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
config.get(CONF_QOS),
config.get(CONF_PAYLOAD_ON),
config.get(CONF_PAYLOAD_OFF),
config.get(CONF_VALUE_TEMPLATE)
value_template
)])