From 71b92265af68f74f4128013321bd70c80fa8c754 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Tue, 15 Aug 2023 09:17:47 +0200 Subject: [PATCH] Include border agent id in response to WS otbr/info (#98394) * Include border agent id in response to WS otbr/info * Assert border agent ID is not None --- homeassistant/components/otbr/websocket_api.py | 5 +++++ tests/components/otbr/test_websocket_api.py | 11 +++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/otbr/websocket_api.py b/homeassistant/components/otbr/websocket_api.py index 9b57cd8ebd1..449f0ccb44d 100644 --- a/homeassistant/components/otbr/websocket_api.py +++ b/homeassistant/components/otbr/websocket_api.py @@ -47,17 +47,22 @@ async def websocket_info( data: OTBRData = hass.data[DOMAIN] try: + border_agent_id = await data.get_border_agent_id() dataset = await data.get_active_dataset() dataset_tlvs = await data.get_active_dataset_tlvs() except HomeAssistantError as exc: connection.send_error(msg["id"], "get_dataset_failed", str(exc)) return + # The border agent ID is checked when the OTBR config entry is setup, + # we can assert it's not None + assert border_agent_id is not None connection.send_result( msg["id"], { "url": data.url, "active_dataset_tlvs": dataset_tlvs.hex() if dataset_tlvs else None, + "border_agent_id": border_agent_id.hex(), "channel": dataset.channel if dataset else None, }, ) diff --git a/tests/components/otbr/test_websocket_api.py b/tests/components/otbr/test_websocket_api.py index f149e89cc45..7877045c8a4 100644 --- a/tests/components/otbr/test_websocket_api.py +++ b/tests/components/otbr/test_websocket_api.py @@ -8,7 +8,7 @@ from homeassistant.components import otbr, thread from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component -from . import BASE_URL, DATASET_CH15, DATASET_CH16 +from . import BASE_URL, DATASET_CH15, DATASET_CH16, TEST_BORDER_AGENT_ID from tests.test_util.aiohttp import AiohttpClientMocker from tests.typing import WebSocketGenerator @@ -31,7 +31,11 @@ async def test_get_info( with patch( "python_otbr_api.OTBR.get_active_dataset", return_value=python_otbr_api.ActiveDataSet(channel=16), - ), patch("python_otbr_api.OTBR.get_active_dataset_tlvs", return_value=DATASET_CH16): + ), patch( + "python_otbr_api.OTBR.get_active_dataset_tlvs", return_value=DATASET_CH16 + ), patch( + "python_otbr_api.OTBR.get_border_agent_id", return_value=TEST_BORDER_AGENT_ID + ): await websocket_client.send_json_auto_id({"type": "otbr/info"}) msg = await websocket_client.receive_json() @@ -40,6 +44,7 @@ async def test_get_info( "url": BASE_URL, "active_dataset_tlvs": DATASET_CH16.hex().lower(), "channel": 16, + "border_agent_id": TEST_BORDER_AGENT_ID.hex(), } @@ -68,6 +73,8 @@ async def test_get_info_fetch_fails( with patch( "python_otbr_api.OTBR.get_active_dataset", side_effect=python_otbr_api.OTBRError, + ), patch( + "python_otbr_api.OTBR.get_border_agent_id", return_value=TEST_BORDER_AGENT_ID ): await websocket_client.send_json_auto_id({"type": "otbr/info"}) msg = await websocket_client.receive_json()