Add test for missimng attributes.
This commit is contained in:
parent
3aad223c95
commit
93a38d39ef
1 changed files with 19 additions and 3 deletions
|
@ -26,19 +26,19 @@ class TestTemplateSensor:
|
||||||
'sensors': {
|
'sensors': {
|
||||||
'test_template_sensor': {
|
'test_template_sensor': {
|
||||||
'value_template':
|
'value_template':
|
||||||
"{{ states.sensor.test_state.state }}"
|
"It {{ states.sensor.test_state.state }}."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('sensor.test_template_sensor')
|
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.states.set('sensor.test_state', 'Works')
|
||||||
self.hass.pool.block_till_done()
|
self.hass.pool.block_till_done()
|
||||||
state = self.hass.states.get('sensor.test_template_sensor')
|
state = self.hass.states.get('sensor.test_template_sensor')
|
||||||
assert state.state == 'Works'
|
assert state.state == 'It Works.'
|
||||||
|
|
||||||
def test_template_syntax_error(self):
|
def test_template_syntax_error(self):
|
||||||
assert sensor.setup(self.hass, {
|
assert sensor.setup(self.hass, {
|
||||||
|
@ -58,6 +58,22 @@ class TestTemplateSensor:
|
||||||
state = self.hass.states.get('sensor.test_template_sensor')
|
state = self.hass.states.get('sensor.test_template_sensor')
|
||||||
assert state.state == 'error'
|
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):
|
def test_invalid_name_does_not_create(self):
|
||||||
assert sensor.setup(self.hass, {
|
assert sensor.setup(self.hass, {
|
||||||
'sensor': {
|
'sensor': {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue