From 78f0716574dbb7f6619b570489f9d34e939a4031 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 17 May 2022 01:22:56 -0500 Subject: [PATCH] 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 Co-authored-by: Paulus Schoutsen --- .../components/websocket_api/commands.py | 10 +++++++--- .../components/websocket_api/test_commands.py | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/websocket_api/commands.py b/homeassistant/components/websocket_api/commands.py index edec628fd2c..61bcb8badf0 100644 --- a/homeassistant/components/websocket_api/commands.py +++ b/homeassistant/components/websocket_api/commands.py @@ -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] diff --git a/tests/components/websocket_api/test_commands.py b/tests/components/websocket_api/test_commands.py index 007e130ff6f..4d3302f7c13 100644 --- a/tests/components/websocket_api/test_commands.py +++ b/tests/components/websocket_api/test_commands.py @@ -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")