Change error state to be 'error' rather than 'unknown', trace error.

This commit is contained in:
pavoni 2016-01-22 16:30:02 +00:00
parent 87a9fd8252
commit ad62591f43
2 changed files with 6 additions and 4 deletions

View file

@ -12,7 +12,6 @@ import logging
from homeassistant.helpers.entity import Entity
from homeassistant.core import EVENT_STATE_CHANGED
from homeassistant.const import (
STATE_UNKNOWN,
ATTR_FRIENDLY_NAME,
CONF_VALUE_TEMPLATE,
ATTR_UNIT_OF_MEASUREMENT)
@ -24,6 +23,8 @@ _LOGGER = logging.getLogger(__name__)
CONF_SENSORS = 'sensors'
STATE_ERROR = 'error'
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
@ -107,5 +108,6 @@ class SensorTemplate(Entity):
def update(self):
try:
self._state = template.render(self.hass, self._template)
except TemplateError:
self._state = STATE_UNKNOWN
except TemplateError as ex:
self._state = STATE_ERROR
_LOGGER.error(ex)

View file

@ -60,4 +60,4 @@ class TestTemplateSensor:
self.hass.states.set('sensor.test_state', 'Works')
self.hass.pool.block_till_done()
state = self.hass.states.get('sensor.test_template_sensor')
assert state.state == 'unknown'
assert state.state == 'error'