Improve detection of entity names in templates (#13432)

* Improve detection of entity names in templates

* Only test variables
This commit is contained in:
Anders Melchiorsen 2018-03-25 12:51:11 +02:00 committed by Paulus Schoutsen
parent 60f6109cbf
commit 22cefc7e64
2 changed files with 9 additions and 2 deletions

View File

@ -13,7 +13,7 @@ from jinja2.sandbox import ImmutableSandboxedEnvironment
from homeassistant.const import (
ATTR_LATITUDE, ATTR_LONGITUDE, ATTR_UNIT_OF_MEASUREMENT, MATCH_ALL,
STATE_UNKNOWN)
from homeassistant.core import State
from homeassistant.core import State, valid_entity_id
from homeassistant.exceptions import TemplateError
from homeassistant.helpers import location as loc_helper
from homeassistant.loader import bind_hass, get_component
@ -73,7 +73,8 @@ def extract_entities(template, variables=None):
extraction_final.append(result[0])
if variables and result[1] in variables and \
isinstance(variables[result[1]], str):
isinstance(variables[result[1]], str) and \
valid_entity_id(variables[result[1]]):
extraction_final.append(variables[result[1]])
if extraction_final:

View File

@ -836,6 +836,12 @@ is_state_attr('device_tracker.phone_2', 'battery', 40)
"{{ is_state(trigger.entity_id, 'off') }}",
{'trigger': {'entity_id': 'input_boolean.switch'}}))
self.assertEqual(
MATCH_ALL,
template.extract_entities(
"{{ is_state('media_player.' ~ where , 'playing') }}",
{'where': 'livingroom'}))
@asyncio.coroutine
def test_state_with_unit(hass):