mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Add test for missimng attributes.
This commit is contained in:
parent
3aad223c95
commit
93a38d39ef
@ -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