1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

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
2017-02-07 03:51:44 -06:00
committed by Paulus Schoutsen
parent f0da576315
commit 063c0e8f44
2 changed files with 55 additions and 1 deletions

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):