Add assistant filter to expose entities list command (#138817)

This commit is contained in:
Michael Hansen
2025-02-18 19:39:44 -06:00
committed by GitHub
parent f8ffbf0506
commit a6bb5dbe2a
2 changed files with 74 additions and 1 deletions

View File

@@ -539,6 +539,70 @@ async def test_list_exposed_entities(
}
async def test_list_exposed_entities_with_filter(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
hass_ws_client: WebSocketGenerator,
) -> None:
"""Test list exposed entities with filter."""
ws_client = await hass_ws_client(hass)
assert await async_setup_component(hass, "homeassistant", {})
await hass.async_block_till_done()
entry1 = entity_registry.async_get_or_create("test", "test", "unique1")
entry2 = entity_registry.async_get_or_create("test", "test", "unique2")
# Expose 1 to Alexa
await ws_client.send_json_auto_id(
{
"type": "homeassistant/expose_entity",
"assistants": ["cloud.alexa"],
"entity_ids": [entry1.entity_id],
"should_expose": True,
}
)
response = await ws_client.receive_json()
assert response["success"]
# Expose 2 to Google
await ws_client.send_json_auto_id(
{
"type": "homeassistant/expose_entity",
"assistants": ["cloud.google_assistant"],
"entity_ids": [entry2.entity_id],
"should_expose": True,
}
)
response = await ws_client.receive_json()
assert response["success"]
# List with filter
await ws_client.send_json_auto_id(
{"type": "homeassistant/expose_entity/list", "assistant": "cloud.alexa"}
)
response = await ws_client.receive_json()
assert response["success"]
assert response["result"] == {
"exposed_entities": {
"test.test_unique1": {"cloud.alexa": True},
},
}
await ws_client.send_json_auto_id(
{
"type": "homeassistant/expose_entity/list",
"assistant": "cloud.google_assistant",
}
)
response = await ws_client.receive_json()
assert response["success"]
assert response["result"] == {
"exposed_entities": {
"test.test_unique2": {"cloud.google_assistant": True},
},
}
async def test_listeners(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None: