From 0e734e629c762c5970cb399f9f6f95a8341c5d1b Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 9 Sep 2022 01:47:33 -0400 Subject: [PATCH] Handle missing supported brands (#78090) --- homeassistant/components/websocket_api/commands.py | 3 +++ tests/components/websocket_api/test_commands.py | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/websocket_api/commands.py b/homeassistant/components/websocket_api/commands.py index 1761323a60d..d4596619241 100644 --- a/homeassistant/components/websocket_api/commands.py +++ b/homeassistant/components/websocket_api/commands.py @@ -722,6 +722,9 @@ async def handle_supported_brands( for int_or_exc in ints_or_excs.values(): if isinstance(int_or_exc, Exception): raise int_or_exc + # Happens if a custom component without supported brands overrides a built-in one with supported brands + if "supported_brands" not in int_or_exc.manifest: + continue data[int_or_exc.domain] = int_or_exc.manifest["supported_brands"] connection.send_result(msg["id"], data) diff --git a/tests/components/websocket_api/test_commands.py b/tests/components/websocket_api/test_commands.py index fe748e2c47c..354a4edeb0d 100644 --- a/tests/components/websocket_api/test_commands.py +++ b/tests/components/websocket_api/test_commands.py @@ -1760,6 +1760,12 @@ async def test_validate_config_invalid(websocket_client, key, config, error): async def test_supported_brands(hass, websocket_client): """Test supported brands.""" + # Custom components without supported brands that override a built-in component with + # supported brand will still be listed in HAS_SUPPORTED_BRANDS and should be ignored. + mock_integration( + hass, + MockModule("override_without_brands"), + ) mock_integration( hass, MockModule("test", partial_manifest={"supported_brands": {"hello": "World"}}), @@ -1773,7 +1779,7 @@ async def test_supported_brands(hass, websocket_client): with patch( "homeassistant.generated.supported_brands.HAS_SUPPORTED_BRANDS", - ("abcd", "test"), + ("abcd", "test", "override_without_brands"), ): await websocket_client.send_json({"id": 7, "type": "supported_brands"}) msg = await websocket_client.receive_json()