Skip to content
Snippets Groups Projects
Commit 574de3b1 authored by Philip Lundrigan's avatar Philip Lundrigan
Browse files

Handle template error

To be more consistent with the other sensor implementations of templates
parent 4e6b01b0
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,7 @@ import requests ...@@ -13,6 +13,7 @@ import requests
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, CONF_VALUE_TEMPLATE, \ from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, CONF_VALUE_TEMPLATE, \
DEVICE_DEFAULT_NAME DEVICE_DEFAULT_NAME
from homeassistant.exceptions import TemplateError
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from homeassistant.util import template, Throttle from homeassistant.util import template, Throttle
...@@ -55,10 +56,15 @@ def setup_platform(hass, config, add_devices, discovery_info=None): ...@@ -55,10 +56,15 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
""" Creates renderer based on variable_template value """ """ Creates renderer based on variable_template value """
if value_template is None: if value_template is None:
return lambda value: value return lambda value: value
else:
return lambda value: template.render(hass, def _render(value):
value_template, try:
{'value': value}) return template.render(hass, value_template, {'value': value})
except TemplateError:
_LOGGER.exception('Error parsing value')
return value
return _render
dev = [] dev = []
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment