mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
Fix entity extraction from Template conditions (#40034)
This commit is contained in:
parent
30b8565548
commit
afde5a7ece
@ -649,13 +649,16 @@ async def async_validate_condition_config(
|
|||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_extract_entities(config: ConfigType) -> Set[str]:
|
def async_extract_entities(config: Union[ConfigType, Template]) -> Set[str]:
|
||||||
"""Extract entities from a condition."""
|
"""Extract entities from a condition."""
|
||||||
referenced: Set[str] = set()
|
referenced: Set[str] = set()
|
||||||
to_process = deque([config])
|
to_process = deque([config])
|
||||||
|
|
||||||
while to_process:
|
while to_process:
|
||||||
config = to_process.popleft()
|
config = to_process.popleft()
|
||||||
|
if isinstance(config, Template):
|
||||||
|
continue
|
||||||
|
|
||||||
condition = config[CONF_CONDITION]
|
condition = config[CONF_CONDITION]
|
||||||
|
|
||||||
if condition in ("and", "not", "or"):
|
if condition in ("and", "not", "or"):
|
||||||
@ -674,13 +677,16 @@ def async_extract_entities(config: ConfigType) -> Set[str]:
|
|||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_extract_devices(config: ConfigType) -> Set[str]:
|
def async_extract_devices(config: Union[ConfigType, Template]) -> Set[str]:
|
||||||
"""Extract devices from a condition."""
|
"""Extract devices from a condition."""
|
||||||
referenced = set()
|
referenced = set()
|
||||||
to_process = deque([config])
|
to_process = deque([config])
|
||||||
|
|
||||||
while to_process:
|
while to_process:
|
||||||
config = to_process.popleft()
|
config = to_process.popleft()
|
||||||
|
if isinstance(config, Template):
|
||||||
|
continue
|
||||||
|
|
||||||
condition = config[CONF_CONDITION]
|
condition = config[CONF_CONDITION]
|
||||||
|
|
||||||
if condition in ("and", "not", "or"):
|
if condition in ("and", "not", "or"):
|
||||||
|
@ -5,6 +5,7 @@ import pytest
|
|||||||
|
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import condition
|
from homeassistant.helpers import condition
|
||||||
|
from homeassistant.helpers.template import Template
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
from homeassistant.util import dt
|
from homeassistant.util import dt
|
||||||
|
|
||||||
@ -807,6 +808,7 @@ async def test_extract_entities():
|
|||||||
"entity_id": ["sensor.temperature_9", "sensor.temperature_10"],
|
"entity_id": ["sensor.temperature_9", "sensor.temperature_10"],
|
||||||
"below": 110,
|
"below": 110,
|
||||||
},
|
},
|
||||||
|
Template("{{ is_state('light.example', 'on') }}"),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
) == {
|
) == {
|
||||||
@ -867,6 +869,7 @@ async def test_extract_devices():
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
Template("{{ is_state('light.example', 'on') }}"),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user