mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Improve detection of entity names in templates (#13432)
* Improve detection of entity names in templates * Only test variables
This commit is contained in:
parent
60f6109cbf
commit
22cefc7e64
@ -13,7 +13,7 @@ from jinja2.sandbox import ImmutableSandboxedEnvironment
|
|||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_LATITUDE, ATTR_LONGITUDE, ATTR_UNIT_OF_MEASUREMENT, MATCH_ALL,
|
ATTR_LATITUDE, ATTR_LONGITUDE, ATTR_UNIT_OF_MEASUREMENT, MATCH_ALL,
|
||||||
STATE_UNKNOWN)
|
STATE_UNKNOWN)
|
||||||
from homeassistant.core import State
|
from homeassistant.core import State, valid_entity_id
|
||||||
from homeassistant.exceptions import TemplateError
|
from homeassistant.exceptions import TemplateError
|
||||||
from homeassistant.helpers import location as loc_helper
|
from homeassistant.helpers import location as loc_helper
|
||||||
from homeassistant.loader import bind_hass, get_component
|
from homeassistant.loader import bind_hass, get_component
|
||||||
@ -73,7 +73,8 @@ def extract_entities(template, variables=None):
|
|||||||
extraction_final.append(result[0])
|
extraction_final.append(result[0])
|
||||||
|
|
||||||
if variables and result[1] in variables and \
|
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]])
|
extraction_final.append(variables[result[1]])
|
||||||
|
|
||||||
if extraction_final:
|
if extraction_final:
|
||||||
|
@ -836,6 +836,12 @@ is_state_attr('device_tracker.phone_2', 'battery', 40)
|
|||||||
"{{ is_state(trigger.entity_id, 'off') }}",
|
"{{ is_state(trigger.entity_id, 'off') }}",
|
||||||
{'trigger': {'entity_id': 'input_boolean.switch'}}))
|
{'trigger': {'entity_id': 'input_boolean.switch'}}))
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
MATCH_ALL,
|
||||||
|
template.extract_entities(
|
||||||
|
"{{ is_state('media_player.' ~ where , 'playing') }}",
|
||||||
|
{'where': 'livingroom'}))
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_state_with_unit(hass):
|
def test_state_with_unit(hass):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user