Make home assistant discoverable via UPnP/SSDP (#79820)
This commit is contained in:
parent
d12cbab6c4
commit
731f618028
20 changed files with 290 additions and 34 deletions
|
@ -5,6 +5,7 @@ from datetime import datetime, timedelta
|
|||
from ipaddress import IPv4Address
|
||||
from unittest.mock import ANY, AsyncMock, patch
|
||||
|
||||
from async_upnp_client.server import UpnpServer
|
||||
from async_upnp_client.ssdp import udn_from_headers
|
||||
from async_upnp_client.ssdp_listener import SsdpListener
|
||||
from async_upnp_client.utils import CaseInsensitiveDict
|
||||
|
@ -34,7 +35,7 @@ async def init_ssdp_component(hass: homeassistant) -> SsdpListener:
|
|||
"""Initialize ssdp component and get SsdpListener."""
|
||||
await async_setup_component(hass, ssdp.DOMAIN, {ssdp.DOMAIN: {}})
|
||||
await hass.async_block_till_done()
|
||||
return hass.data[ssdp.DOMAIN]._ssdp_listeners[0]
|
||||
return hass.data[ssdp.DOMAIN][ssdp.SSDP_SCANNER]._ssdp_listeners[0]
|
||||
|
||||
|
||||
@patch(
|
||||
|
@ -407,7 +408,7 @@ async def test_discovery_from_advertisement_sets_ssdp_st(
|
|||
|
||||
|
||||
@patch(
|
||||
"homeassistant.components.ssdp.Scanner._async_build_source_set",
|
||||
"homeassistant.components.ssdp.async_build_source_set",
|
||||
return_value={IPv4Address("192.168.1.1")},
|
||||
)
|
||||
@pytest.mark.usefixtures("mock_get_source_ip")
|
||||
|
@ -668,7 +669,7 @@ async def test_async_detect_interfaces_setting_empty_route(
|
|||
"""Test without default interface config and the route returns nothing."""
|
||||
await init_ssdp_component(hass)
|
||||
|
||||
ssdp_listeners = hass.data[ssdp.DOMAIN]._ssdp_listeners
|
||||
ssdp_listeners = hass.data[ssdp.DOMAIN][ssdp.SSDP_SCANNER]._ssdp_listeners
|
||||
sources = {ssdp_listener.source for ssdp_listener in ssdp_listeners}
|
||||
assert sources == {("2001:db8::%1", 0, 0, 1), ("192.168.1.5", 0)}
|
||||
|
||||
|
@ -698,14 +699,25 @@ async def test_bind_failure_skips_adapter(
|
|||
raise OSError
|
||||
|
||||
SsdpListener.async_start = _async_start
|
||||
UpnpServer.async_start = _async_start
|
||||
await init_ssdp_component(hass)
|
||||
|
||||
assert "Failed to setup listener for" in caplog.text
|
||||
|
||||
ssdp_listeners = hass.data[ssdp.DOMAIN]._ssdp_listeners
|
||||
ssdp_listeners: list[SsdpListener] = hass.data[ssdp.DOMAIN][
|
||||
ssdp.SSDP_SCANNER
|
||||
]._ssdp_listeners
|
||||
sources = {ssdp_listener.source for ssdp_listener in ssdp_listeners}
|
||||
assert sources == {("192.168.1.5", 0)} # Note no SsdpListener for IPv6 address.
|
||||
|
||||
assert "Failed to setup server for" in caplog.text
|
||||
|
||||
upnp_servers: list[UpnpServer] = hass.data[ssdp.DOMAIN][
|
||||
ssdp.UPNP_SERVER
|
||||
]._upnp_servers
|
||||
sources = {upnp_server.source for upnp_server in upnp_servers}
|
||||
assert sources == {("192.168.1.5", 0)} # Note no UpnpServer for IPv6 address.
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_get_source_ip")
|
||||
@patch(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue