Extract entity ids from all templates (#17902)

This commit is contained in:
Anders Melchiorsen
2018-10-29 08:03:10 +01:00
committed by Paulus Schoutsen
parent 3e6de21302
commit e5c97fdcab
2 changed files with 53 additions and 14 deletions
@@ -106,7 +106,7 @@ class TestBinarySensorTemplate(unittest.TestCase):
'platform': 'template',
'sensors': {
'test_template_sensor': {
'value_template': "State",
'value_template': "{{ states.sensor.xyz.state }}",
'icon_template':
"{% if "
"states.binary_sensor.test_state.state == "
@@ -137,7 +137,7 @@ class TestBinarySensorTemplate(unittest.TestCase):
'platform': 'template',
'sensors': {
'test_template_sensor': {
'value_template': "State",
'value_template': "{{ states.sensor.xyz.state }}",
'entity_picture_template':
"{% if "
"states.binary_sensor.test_state.state == "
@@ -160,6 +160,30 @@ class TestBinarySensorTemplate(unittest.TestCase):
state = self.hass.states.get('binary_sensor.test_template_sensor')
assert state.attributes['entity_picture'] == '/local/sensor.png'
@mock.patch('homeassistant.components.binary_sensor.template.'
'BinarySensorTemplate._async_render')
def test_match_all(self, _async_render):
"""Test MATCH_ALL in template."""
with assert_setup_component(1):
assert setup.setup_component(self.hass, 'binary_sensor', {
'binary_sensor': {
'platform': 'template',
'sensors': {
'match_all_template_sensor': {
'value_template': "{{ 42 }}",
},
}
}
})
self.hass.start()
self.hass.block_till_done()
init_calls = len(_async_render.mock_calls)
self.hass.states.set('sensor.any_state', 'update')
self.hass.block_till_done()
assert len(_async_render.mock_calls) > init_calls
def test_attributes(self):
"""Test the attributes."""
vs = run_callback_threadsafe(