mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Add entity_picture_template options to Template Cover, Template Light, Template Sensor, and Template Switch (#9854)
* Re-adding cover * Re-adding light * Re-adding sensor * Re-adding switch * Re-added tests * Fixing missing imports in rebased test * Fixing broken tests * Owner-requested changes * Owner-requested changes * Fixed exception
This commit is contained in:
committed by
Paulus Schoutsen
parent
05ece53ec2
commit
646c03eea1
@@ -625,3 +625,97 @@ class TestTemplateLight:
|
||||
assert state is not None
|
||||
|
||||
assert state.attributes.get('friendly_name') == 'Template light'
|
||||
|
||||
def test_icon_template(self):
|
||||
"""Test icon template."""
|
||||
with assert_setup_component(1, 'light'):
|
||||
assert setup.setup_component(self.hass, 'light', {
|
||||
'light': {
|
||||
'platform': 'template',
|
||||
'lights': {
|
||||
'test_template_light': {
|
||||
'friendly_name': 'Template light',
|
||||
'value_template': "{{ 1 == 1 }}",
|
||||
'turn_on': {
|
||||
'service': 'light.turn_on',
|
||||
'entity_id': 'light.test_state'
|
||||
},
|
||||
'turn_off': {
|
||||
'service': 'light.turn_off',
|
||||
'entity_id': 'light.test_state'
|
||||
},
|
||||
'set_level': {
|
||||
'service': 'light.turn_on',
|
||||
'data_template': {
|
||||
'entity_id': 'light.test_state',
|
||||
'brightness': '{{brightness}}'
|
||||
}
|
||||
},
|
||||
'icon_template':
|
||||
"{% if states.light.test_state.state %}"
|
||||
"mdi:check"
|
||||
"{% endif %}"
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
self.hass.start()
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('light.test_template_light')
|
||||
assert state.attributes.get('icon') == ''
|
||||
|
||||
state = self.hass.states.set('light.test_state', STATE_ON)
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('light.test_template_light')
|
||||
|
||||
assert state.attributes['icon'] == 'mdi:check'
|
||||
|
||||
def test_entity_picture_template(self):
|
||||
"""Test entity_picture template."""
|
||||
with assert_setup_component(1, 'light'):
|
||||
assert setup.setup_component(self.hass, 'light', {
|
||||
'light': {
|
||||
'platform': 'template',
|
||||
'lights': {
|
||||
'test_template_light': {
|
||||
'friendly_name': 'Template light',
|
||||
'value_template': "{{ 1 == 1 }}",
|
||||
'turn_on': {
|
||||
'service': 'light.turn_on',
|
||||
'entity_id': 'light.test_state'
|
||||
},
|
||||
'turn_off': {
|
||||
'service': 'light.turn_off',
|
||||
'entity_id': 'light.test_state'
|
||||
},
|
||||
'set_level': {
|
||||
'service': 'light.turn_on',
|
||||
'data_template': {
|
||||
'entity_id': 'light.test_state',
|
||||
'brightness': '{{brightness}}'
|
||||
}
|
||||
},
|
||||
'entity_picture_template':
|
||||
"{% if states.light.test_state.state %}"
|
||||
"/local/light.png"
|
||||
"{% endif %}"
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
self.hass.start()
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('light.test_template_light')
|
||||
assert state.attributes.get('entity_picture') == ''
|
||||
|
||||
state = self.hass.states.set('light.test_state', STATE_ON)
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('light.test_template_light')
|
||||
|
||||
assert state.attributes['entity_picture'] == '/local/light.png'
|
||||
|
||||
Reference in New Issue
Block a user