diff --git a/homeassistant/components/thread/discovery.py b/homeassistant/components/thread/discovery.py index 4f0df6b1533..d4e47c31dd2 100644 --- a/homeassistant/components/thread/discovery.py +++ b/homeassistant/components/thread/discovery.py @@ -8,7 +8,13 @@ import logging from typing import cast from python_otbr_api.mdns import StateBitmap -from zeroconf import BadTypeInNameException, DNSPointer, ServiceListener, Zeroconf +from zeroconf import ( + BadTypeInNameException, + DNSPointer, + ServiceListener, + Zeroconf, + instance_name_from_service_info, +) from zeroconf.asyncio import AsyncServiceInfo, AsyncZeroconf from homeassistant.components import zeroconf @@ -37,6 +43,7 @@ TYPE_PTR = 12 class ThreadRouterDiscoveryData: """Thread router discovery data.""" + instance_name: str addresses: list[str] border_agent_id: str | None brand: str | None @@ -89,6 +96,7 @@ def async_discovery_data_from_service( unconfigured = True return ThreadRouterDiscoveryData( + instance_name=instance_name_from_service_info(service), addresses=service.parsed_addresses(), border_agent_id=border_agent_id.hex() if border_agent_id is not None else None, brand=brand, diff --git a/tests/components/thread/test_discovery.py b/tests/components/thread/test_discovery.py index d9895aa72b2..3cf195ad40e 100644 --- a/tests/components/thread/test_discovery.py +++ b/tests/components/thread/test_discovery.py @@ -74,6 +74,7 @@ async def test_discover_routers( assert discovered[-1] == ( "aeeb2f594b570bbf", discovery.ThreadRouterDiscoveryData( + instance_name="HomeAssistant OpenThreadBorderRouter #0BBF", addresses=["192.168.0.115"], border_agent_id="230c6a1ac57f6f4be262acf32e5ef52c", brand="homeassistant", @@ -101,6 +102,7 @@ async def test_discover_routers( assert discovered[-1] == ( "f6a99b425a67abed", discovery.ThreadRouterDiscoveryData( + instance_name="Google-Nest-Hub-#ABED", addresses=["192.168.0.124"], border_agent_id="bc3740c3e963aa8735bebecd7cc503c7", brand="google", @@ -180,6 +182,7 @@ async def test_discover_routers_unconfigured( router_discovered_removed.assert_called_once_with( "aeeb2f594b570bbf", discovery.ThreadRouterDiscoveryData( + instance_name="HomeAssistant OpenThreadBorderRouter #0BBF", addresses=["192.168.0.115"], border_agent_id="230c6a1ac57f6f4be262acf32e5ef52c", brand="homeassistant", @@ -226,6 +229,7 @@ async def test_discover_routers_bad_or_missing_optional_data( router_discovered_removed.assert_called_once_with( "aeeb2f594b570bbf", discovery.ThreadRouterDiscoveryData( + instance_name="HomeAssistant OpenThreadBorderRouter #0BBF", addresses=["192.168.0.115"], border_agent_id="230c6a1ac57f6f4be262acf32e5ef52c", brand=None, diff --git a/tests/components/thread/test_websocket_api.py b/tests/components/thread/test_websocket_api.py index f3390a9d8b8..fb429acc3e0 100644 --- a/tests/components/thread/test_websocket_api.py +++ b/tests/components/thread/test_websocket_api.py @@ -353,6 +353,7 @@ async def test_discover_routers( assert msg == { "event": { "data": { + "instance_name": "HomeAssistant OpenThreadBorderRouter #0BBF", "addresses": ["192.168.0.115"], "border_agent_id": "230c6a1ac57f6f4be262acf32e5ef52c", "brand": "homeassistant", @@ -388,6 +389,7 @@ async def test_discover_routers( "brand": "google", "extended_address": "f6a99b425a67abed", "extended_pan_id": "9e75e256f61409a3", + "instance_name": "Google-Nest-Hub-#ABED", "model_name": "Google Nest Hub", "network_name": "NEST-PAN-E1AF", "server": "2d99f293-cd8e-2770-8dd2-6675de9fa000.local.",