Fix Assist skipping entities that are hidden or have entity category (#87096)
Skipping entities that are hidden or have entity category
This commit is contained in:
parent
97fac1dde8
commit
f32f46aff5
2 changed files with 52 additions and 4 deletions
|
@ -403,16 +403,20 @@ class DefaultAgent(AbstractConversationAgent):
|
||||||
|
|
||||||
entity = entities.async_get(state.entity_id)
|
entity = entities.async_get(state.entity_id)
|
||||||
if entity is not None:
|
if entity is not None:
|
||||||
if entity.entity_category:
|
if entity.entity_category or entity.hidden:
|
||||||
# Skip configuration/diagnostic entities
|
# Skip configuration/diagnostic/hidden entities
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if entity.aliases:
|
if entity.aliases:
|
||||||
for alias in entity.aliases:
|
for alias in entity.aliases:
|
||||||
names.append((alias, state.entity_id, context))
|
names.append((alias, state.entity_id, context))
|
||||||
|
|
||||||
# Default name
|
# Default name
|
||||||
names.append((state.name, state.entity_id, context))
|
names.append((state.name, state.entity_id, context))
|
||||||
|
|
||||||
|
else:
|
||||||
|
# Default name
|
||||||
|
names.append((state.name, state.entity_id, context))
|
||||||
|
|
||||||
self._names_list = TextSlotList.from_tuples(names, allow_template=False)
|
self._names_list = TextSlotList.from_tuples(names, allow_template=False)
|
||||||
return self._names_list
|
return self._names_list
|
||||||
|
|
44
tests/components/conversation/test_default_agent.py
Normal file
44
tests/components/conversation/test_default_agent.py
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
"""Test for the default agent."""
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from homeassistant.components import conversation
|
||||||
|
from homeassistant.core import DOMAIN as HASS_DOMAIN, Context
|
||||||
|
from homeassistant.helpers import entity, entity_registry, intent
|
||||||
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
from tests.common import async_mock_service
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
async def init_components(hass):
|
||||||
|
"""Initialize relevant components with empty configs."""
|
||||||
|
assert await async_setup_component(hass, "homeassistant", {})
|
||||||
|
assert await async_setup_component(hass, "conversation", {})
|
||||||
|
assert await async_setup_component(hass, "intent", {})
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"er_kwargs",
|
||||||
|
[
|
||||||
|
{"hidden_by": entity_registry.RegistryEntryHider.USER},
|
||||||
|
{"hidden_by": entity_registry.RegistryEntryHider.INTEGRATION},
|
||||||
|
{"entity_category": entity.EntityCategory.CONFIG},
|
||||||
|
{"entity_category": entity.EntityCategory.DIAGNOSTIC},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
async def test_hidden_entities_skipped(hass, init_components, er_kwargs):
|
||||||
|
"""Test we skip hidden entities."""
|
||||||
|
|
||||||
|
er = entity_registry.async_get(hass)
|
||||||
|
er.async_get_or_create(
|
||||||
|
"light", "demo", "1234", suggested_object_id="Test light", **er_kwargs
|
||||||
|
)
|
||||||
|
hass.states.async_set("light.test_light", "off")
|
||||||
|
calls = async_mock_service(hass, HASS_DOMAIN, "turn_on")
|
||||||
|
result = await conversation.async_converse(
|
||||||
|
hass, "turn on test light", None, Context(), None
|
||||||
|
)
|
||||||
|
|
||||||
|
assert len(calls) == 0
|
||||||
|
assert result.response.response_type == intent.IntentResponseType.ERROR
|
||||||
|
assert result.response.error_code == intent.IntentResponseErrorCode.NO_INTENT_MATCH
|
Loading…
Add table
Reference in a new issue