mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Store instance name in Thread router discovery (#127253)
* Store instance name in Thread router discovery Store the DNS-SD instance name in the Thread router discovery message. The instance name is the actual name given to a Thread border router, e.g. when configuring the name of a Thread border router in Apple Home the name appears as the DNS-SD instance name. This will allow to make the Thread border router list more user friendly. * Use instance_name_from_service_info to get instance name
This commit is contained in:
parent
a83d38a5fe
commit
88ad7e98e0
@ -8,7 +8,13 @@ import logging
|
|||||||
from typing import cast
|
from typing import cast
|
||||||
|
|
||||||
from python_otbr_api.mdns import StateBitmap
|
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 zeroconf.asyncio import AsyncServiceInfo, AsyncZeroconf
|
||||||
|
|
||||||
from homeassistant.components import zeroconf
|
from homeassistant.components import zeroconf
|
||||||
@ -37,6 +43,7 @@ TYPE_PTR = 12
|
|||||||
class ThreadRouterDiscoveryData:
|
class ThreadRouterDiscoveryData:
|
||||||
"""Thread router discovery data."""
|
"""Thread router discovery data."""
|
||||||
|
|
||||||
|
instance_name: str
|
||||||
addresses: list[str]
|
addresses: list[str]
|
||||||
border_agent_id: str | None
|
border_agent_id: str | None
|
||||||
brand: str | None
|
brand: str | None
|
||||||
@ -89,6 +96,7 @@ def async_discovery_data_from_service(
|
|||||||
unconfigured = True
|
unconfigured = True
|
||||||
|
|
||||||
return ThreadRouterDiscoveryData(
|
return ThreadRouterDiscoveryData(
|
||||||
|
instance_name=instance_name_from_service_info(service),
|
||||||
addresses=service.parsed_addresses(),
|
addresses=service.parsed_addresses(),
|
||||||
border_agent_id=border_agent_id.hex() if border_agent_id is not None else None,
|
border_agent_id=border_agent_id.hex() if border_agent_id is not None else None,
|
||||||
brand=brand,
|
brand=brand,
|
||||||
|
@ -74,6 +74,7 @@ async def test_discover_routers(
|
|||||||
assert discovered[-1] == (
|
assert discovered[-1] == (
|
||||||
"aeeb2f594b570bbf",
|
"aeeb2f594b570bbf",
|
||||||
discovery.ThreadRouterDiscoveryData(
|
discovery.ThreadRouterDiscoveryData(
|
||||||
|
instance_name="HomeAssistant OpenThreadBorderRouter #0BBF",
|
||||||
addresses=["192.168.0.115"],
|
addresses=["192.168.0.115"],
|
||||||
border_agent_id="230c6a1ac57f6f4be262acf32e5ef52c",
|
border_agent_id="230c6a1ac57f6f4be262acf32e5ef52c",
|
||||||
brand="homeassistant",
|
brand="homeassistant",
|
||||||
@ -101,6 +102,7 @@ async def test_discover_routers(
|
|||||||
assert discovered[-1] == (
|
assert discovered[-1] == (
|
||||||
"f6a99b425a67abed",
|
"f6a99b425a67abed",
|
||||||
discovery.ThreadRouterDiscoveryData(
|
discovery.ThreadRouterDiscoveryData(
|
||||||
|
instance_name="Google-Nest-Hub-#ABED",
|
||||||
addresses=["192.168.0.124"],
|
addresses=["192.168.0.124"],
|
||||||
border_agent_id="bc3740c3e963aa8735bebecd7cc503c7",
|
border_agent_id="bc3740c3e963aa8735bebecd7cc503c7",
|
||||||
brand="google",
|
brand="google",
|
||||||
@ -180,6 +182,7 @@ async def test_discover_routers_unconfigured(
|
|||||||
router_discovered_removed.assert_called_once_with(
|
router_discovered_removed.assert_called_once_with(
|
||||||
"aeeb2f594b570bbf",
|
"aeeb2f594b570bbf",
|
||||||
discovery.ThreadRouterDiscoveryData(
|
discovery.ThreadRouterDiscoveryData(
|
||||||
|
instance_name="HomeAssistant OpenThreadBorderRouter #0BBF",
|
||||||
addresses=["192.168.0.115"],
|
addresses=["192.168.0.115"],
|
||||||
border_agent_id="230c6a1ac57f6f4be262acf32e5ef52c",
|
border_agent_id="230c6a1ac57f6f4be262acf32e5ef52c",
|
||||||
brand="homeassistant",
|
brand="homeassistant",
|
||||||
@ -226,6 +229,7 @@ async def test_discover_routers_bad_or_missing_optional_data(
|
|||||||
router_discovered_removed.assert_called_once_with(
|
router_discovered_removed.assert_called_once_with(
|
||||||
"aeeb2f594b570bbf",
|
"aeeb2f594b570bbf",
|
||||||
discovery.ThreadRouterDiscoveryData(
|
discovery.ThreadRouterDiscoveryData(
|
||||||
|
instance_name="HomeAssistant OpenThreadBorderRouter #0BBF",
|
||||||
addresses=["192.168.0.115"],
|
addresses=["192.168.0.115"],
|
||||||
border_agent_id="230c6a1ac57f6f4be262acf32e5ef52c",
|
border_agent_id="230c6a1ac57f6f4be262acf32e5ef52c",
|
||||||
brand=None,
|
brand=None,
|
||||||
|
@ -353,6 +353,7 @@ async def test_discover_routers(
|
|||||||
assert msg == {
|
assert msg == {
|
||||||
"event": {
|
"event": {
|
||||||
"data": {
|
"data": {
|
||||||
|
"instance_name": "HomeAssistant OpenThreadBorderRouter #0BBF",
|
||||||
"addresses": ["192.168.0.115"],
|
"addresses": ["192.168.0.115"],
|
||||||
"border_agent_id": "230c6a1ac57f6f4be262acf32e5ef52c",
|
"border_agent_id": "230c6a1ac57f6f4be262acf32e5ef52c",
|
||||||
"brand": "homeassistant",
|
"brand": "homeassistant",
|
||||||
@ -388,6 +389,7 @@ async def test_discover_routers(
|
|||||||
"brand": "google",
|
"brand": "google",
|
||||||
"extended_address": "f6a99b425a67abed",
|
"extended_address": "f6a99b425a67abed",
|
||||||
"extended_pan_id": "9e75e256f61409a3",
|
"extended_pan_id": "9e75e256f61409a3",
|
||||||
|
"instance_name": "Google-Nest-Hub-#ABED",
|
||||||
"model_name": "Google Nest Hub",
|
"model_name": "Google Nest Hub",
|
||||||
"network_name": "NEST-PAN-E1AF",
|
"network_name": "NEST-PAN-E1AF",
|
||||||
"server": "2d99f293-cd8e-2770-8dd2-6675de9fa000.local.",
|
"server": "2d99f293-cd8e-2770-8dd2-6675de9fa000.local.",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user