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