mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Merge pull request #1099 from balloob/sensor_template_startup_error
Sensor template startup error
This commit is contained in:
commit
b14f7f7ed0
@ -126,4 +126,9 @@ class SensorTemplate(Entity):
|
||||
self._state = template.render(self.hass, self._template)
|
||||
except TemplateError as ex:
|
||||
self._state = STATE_ERROR
|
||||
if ex.args and ex.args[0].startswith(
|
||||
"UndefinedError: 'None' has no attribute"):
|
||||
# Common during HA startup - so just a warning
|
||||
_LOGGER.warning(ex)
|
||||
return
|
||||
_LOGGER.error(ex)
|
||||
|
@ -26,19 +26,19 @@ class TestTemplateSensor:
|
||||
'sensors': {
|
||||
'test_template_sensor': {
|
||||
'value_template':
|
||||
"{{ states.sensor.test_state.state }}"
|
||||
"It {{ states.sensor.test_state.state }}."
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
state = self.hass.states.get('sensor.test_template_sensor')
|
||||
assert state.state == ''
|
||||
assert state.state == 'It .'
|
||||
|
||||
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 == 'Works'
|
||||
assert state.state == 'It Works.'
|
||||
|
||||
def test_template_syntax_error(self):
|
||||
assert sensor.setup(self.hass, {
|
||||
@ -58,6 +58,22 @@ class TestTemplateSensor:
|
||||
state = self.hass.states.get('sensor.test_template_sensor')
|
||||
assert state.state == 'error'
|
||||
|
||||
def test_template_attribute_missing(self):
|
||||
assert sensor.setup(self.hass, {
|
||||
'sensor': {
|
||||
'platform': 'template',
|
||||
'sensors': {
|
||||
'test_template_sensor': {
|
||||
'value_template':
|
||||
"It {{ states.sensor.test_state.attributes.missing }}."
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
state = self.hass.states.get('sensor.test_template_sensor')
|
||||
assert state.state == 'error'
|
||||
|
||||
def test_invalid_name_does_not_create(self):
|
||||
assert sensor.setup(self.hass, {
|
||||
'sensor': {
|
||||
|
Loading…
x
Reference in New Issue
Block a user