mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Fix UPNP access to SSDP info (#65728)
This commit is contained in:
parent
2f46382565
commit
d753f4a2e7
@ -12,7 +12,7 @@ from async_upnp_client.exceptions import UpnpError
|
||||
from async_upnp_client.profiles.igd import IgdDevice
|
||||
|
||||
from homeassistant.components import ssdp
|
||||
from homeassistant.components.ssdp import SsdpChange
|
||||
from homeassistant.components.ssdp import SsdpChange, SsdpServiceInfo
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
@ -71,19 +71,22 @@ class Device:
|
||||
return device
|
||||
|
||||
async def async_ssdp_callback(
|
||||
self, headers: Mapping[str, Any], change: SsdpChange
|
||||
self, service_info: SsdpServiceInfo, change: SsdpChange
|
||||
) -> None:
|
||||
"""SSDP callback, update if needed."""
|
||||
_LOGGER.debug("SSDP Callback, change: %s, headers: %s", change, headers)
|
||||
if ssdp.ATTR_SSDP_LOCATION not in headers:
|
||||
_LOGGER.debug(
|
||||
"SSDP Callback, change: %s, headers: %s", change, service_info.ssdp_headers
|
||||
)
|
||||
if service_info.ssdp_location is None:
|
||||
return
|
||||
|
||||
location = headers[ssdp.ATTR_SSDP_LOCATION]
|
||||
device = self._igd_device.device
|
||||
if location == device.device_url:
|
||||
if service_info.ssdp_location == device.device_url:
|
||||
return
|
||||
|
||||
new_upnp_device = await async_create_upnp_device(self.hass, location)
|
||||
new_upnp_device = await async_create_upnp_device(
|
||||
self.hass, service_info.ssdp_location
|
||||
)
|
||||
device.reinit(new_upnp_device)
|
||||
|
||||
@property
|
||||
|
@ -45,8 +45,13 @@ async def test_reinitialize_device(
|
||||
|
||||
# Reinit.
|
||||
new_location = "http://192.168.1.1:12345/desc.xml"
|
||||
headers = {
|
||||
ssdp.ATTR_SSDP_LOCATION: new_location,
|
||||
}
|
||||
await device.async_ssdp_callback(headers, ...)
|
||||
await device.async_ssdp_callback(
|
||||
ssdp.SsdpServiceInfo(
|
||||
ssdp_usn="mock_usn",
|
||||
ssdp_st="mock_st",
|
||||
ssdp_location="http://192.168.1.1:12345/desc.xml",
|
||||
upnp={},
|
||||
),
|
||||
...,
|
||||
)
|
||||
assert device._igd_device.device.device_url == new_location
|
||||
|
Loading…
x
Reference in New Issue
Block a user