Remove exception handling for templates
It is now handled in the layers belowpull/732/head
parent
ab9ab532c8
commit
a84ff14b00
|
@ -9,7 +9,6 @@ https://home-assistant.io/components/sensor.rest/
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
import requests
|
import requests
|
||||||
import jinja2.exceptions
|
|
||||||
|
|
||||||
from homeassistant.const import CONF_VALUE_TEMPLATE
|
from homeassistant.const import CONF_VALUE_TEMPLATE
|
||||||
from homeassistant.util import template, Throttle
|
from homeassistant.util import template, Throttle
|
||||||
|
@ -59,18 +58,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
'Please check the URL in the configuration file.')
|
'Please check the URL in the configuration file.')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
value_template = config.get(CONF_VALUE_TEMPLATE)
|
|
||||||
data = response.text
|
|
||||||
if value_template is not None:
|
|
||||||
try:
|
|
||||||
template.render_with_possible_json_value(hass,
|
|
||||||
value_template,
|
|
||||||
data)
|
|
||||||
except jinja2.exceptions.UndefinedError:
|
|
||||||
_LOGGER.error('Template "%s" not found in response: "%s"',
|
|
||||||
value_template, data)
|
|
||||||
return False
|
|
||||||
|
|
||||||
if use_get:
|
if use_get:
|
||||||
rest = RestDataGet(resource, verify_ssl)
|
rest = RestDataGet(resource, verify_ssl)
|
||||||
elif use_post:
|
elif use_post:
|
||||||
|
@ -121,7 +108,7 @@ class RestSensor(Entity):
|
||||||
else:
|
else:
|
||||||
if self._value_template is not None:
|
if self._value_template is not None:
|
||||||
value = template.render_with_possible_json_value(
|
value = template.render_with_possible_json_value(
|
||||||
self._hass, self._value_template, value)
|
self._hass, self._value_template, value, 'N/A')
|
||||||
self._state = value
|
self._state = value
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue