Ensure entity names are not hassil templates (#132184)

pull/132195/head
Michael Hansen 2024-12-03 12:37:05 -06:00 committed by Franck Nijhof
parent 22b353f7d5
commit 512ac7d572
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
2 changed files with 37 additions and 1 deletions

View File

@ -711,7 +711,7 @@ class DefaultAgent(ConversationEntity):
for name_tuple in self._get_entity_name_tuples(exposed=False):
self._unexposed_names_trie.insert(
name_tuple[0].lower(),
TextSlotValue.from_tuple(name_tuple),
TextSlotValue.from_tuple(name_tuple, allow_template=False),
)
# Build filtered slot list

View File

@ -3013,3 +3013,39 @@ async def test_entities_filtered_by_input(hass: HomeAssistant) -> None:
assert len(name_list.values) == 2
assert name_list.values[0].text_in.text == "test light"
assert name_list.values[1].text_in.text == "test light"
@pytest.mark.usefixtures("init_components")
async def test_entities_names_are_not_templates(hass: HomeAssistant) -> None:
"""Test that entities names are not treated as hassil templates."""
# Contains hassil template characters
hass.states.async_set(
"light.test_light", "off", attributes={ATTR_FRIENDLY_NAME: "<test [light"}
)
async_mock_service(hass, LIGHT_DOMAIN, "turn_on")
# Exposed
result = await conversation.async_converse(
hass,
"turn on <test [light",
None,
Context(),
language=hass.config.language,
)
assert result is not None
assert result.response.response_type == intent.IntentResponseType.ACTION_DONE
# Not exposed
expose_entity(hass, "light.test_light", False)
result = await conversation.async_converse(
hass,
"turn on <test [light",
None,
Context(),
language=hass.config.language,
)
assert result is not None
assert result.response.response_type == intent.IntentResponseType.ERROR