Change error state to be 'error' rather than 'unknown', trace error.
This commit is contained in:
parent
87a9fd8252
commit
ad62591f43
2 changed files with 6 additions and 4 deletions
|
@ -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)
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue