Fix UPNP access to SSDP info (#65728)

This commit is contained in:
Paulus Schoutsen 2022-02-04 21:33:53 -08:00 committed by GitHub
parent 2f46382565
commit d753f4a2e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 11 deletions

View File

@ -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

View File

@ -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