Add support for specifying the integrations manifest/list fetches (#71982)

* Add support for specifying the integrations manifest/list fetches

See https://github.com/home-assistant/core/pull/71979 for
the motovation

* Update homeassistant/components/websocket_api/commands.py

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
pull/71988/head
J. Nick Koston 2022-05-17 01:22:56 -05:00 committed by GitHub
parent ddecf76f6f
commit 78f0716574
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 3 deletions

View File

@ -359,15 +359,19 @@ def handle_get_config(
connection.send_result(msg["id"], hass.config.as_dict())
@decorators.websocket_command({vol.Required("type"): "manifest/list"})
@decorators.websocket_command(
{vol.Required("type"): "manifest/list", vol.Optional("integrations"): [str]}
)
@decorators.async_response
async def handle_manifest_list(
hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
) -> None:
"""Handle integrations command."""
loaded_integrations = async_get_loaded_integrations(hass)
wanted_integrations = msg.get("integrations")
if wanted_integrations is None:
wanted_integrations = async_get_loaded_integrations(hass)
integrations = await asyncio.gather(
*(async_get_integration(hass, domain) for domain in loaded_integrations)
*(async_get_integration(hass, domain) for domain in wanted_integrations)
)
connection.send_result(
msg["id"], [integration.manifest for integration in integrations]

View File

@ -1351,6 +1351,25 @@ async def test_manifest_list(hass, websocket_client):
]
async def test_manifest_list_specific_integrations(hass, websocket_client):
"""Test loading manifests for specific integrations."""
websocket_api = await async_get_integration(hass, "websocket_api")
await websocket_client.send_json(
{"id": 5, "type": "manifest/list", "integrations": ["hue", "websocket_api"]}
)
hue = await async_get_integration(hass, "hue")
msg = await websocket_client.receive_json()
assert msg["id"] == 5
assert msg["type"] == const.TYPE_RESULT
assert msg["success"]
assert sorted(msg["result"], key=lambda manifest: manifest["domain"]) == [
hue.manifest,
websocket_api.manifest,
]
async def test_manifest_get(hass, websocket_client):
"""Test getting a manifest."""
hue = await async_get_integration(hass, "hue")