Add icon_template to template sensor (#5766)

* Add icon_template to template sensor

* Update test_template.py

* Update test_template.py again

* Update template.py

* Update test_template.py

* Update test_template.py
This commit is contained in:
Trevor authored and Paulus Schoutsen committed 2017-02-07 01:51:44 -08:00
1 parent f0da576315
commit 063c0e8f44
2 files changed
+55 -1

No files matched your search

+27
View File
@@ -41,6 +41,33 @@ class TestTemplateSensor:
state = self.hass.states.get('sensor.test_template_sensor')
assert state.state == 'It Works.'
def test_icon_template(self):
"""Test icon template."""
with assert_setup_component(1):
assert setup_component(self.hass, 'sensor', {
'sensor': {
'platform': 'template',
'sensors': {
'test_template_sensor': {
'value_template': "State",
'icon_template':
"{% if states.sensor.test_state.state == "
"'Works' %}"
"mdi:check"
"{% endif %}"
}
}
}
})
state = self.hass.states.get('sensor.test_template_sensor')
assert 'icon' not in state.attributes
self.hass.states.set('sensor.test_state', 'Works')
self.hass.block_till_done()
state = self.hass.states.get('sensor.test_template_sensor')
assert state.attributes['icon'] == 'mdi:check'
def test_template_syntax_error(self):
"""Test templating syntax error."""
with assert_setup_component(0):