mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 06:47:09 +00:00
Handle template error
To be more consistent with the other sensor implementations of templates
This commit is contained in:
parent
4e6b01b0b9
commit
574de3b1b6
@ -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):
|
|||||||
""" 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 = []
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user