mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Fix upnp first discovered device is used (#44151)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
8fe5e61cbf
commit
05f9fb80c8
@ -43,6 +43,8 @@ async def async_discover_and_construct(
|
||||
) -> Device:
|
||||
"""Discovery devices and construct a Device for one."""
|
||||
# pylint: disable=invalid-name
|
||||
_LOGGER.debug("Constructing device: %s::%s", udn, st)
|
||||
|
||||
discovery_infos = await Device.async_discover(hass)
|
||||
_LOGGER.debug("Discovered devices: %s", discovery_infos)
|
||||
if not discovery_infos:
|
||||
@ -53,7 +55,7 @@ async def async_discover_and_construct(
|
||||
# Get the discovery info with specified UDN/ST.
|
||||
filtered = [di for di in discovery_infos if di[DISCOVERY_UDN] == udn]
|
||||
if st:
|
||||
filtered = [di for di in discovery_infos if di[DISCOVERY_ST] == st]
|
||||
filtered = [di for di in filtered if di[DISCOVERY_ST] == st]
|
||||
if not filtered:
|
||||
_LOGGER.warning(
|
||||
'Wanted UPnP/IGD device with UDN/ST "%s"/"%s" not found, aborting',
|
||||
@ -74,6 +76,7 @@ async def async_discover_and_construct(
|
||||
)
|
||||
_LOGGER.info("Detected multiple UPnP/IGD devices, using: %s", device_name)
|
||||
|
||||
_LOGGER.debug("Constructing from discovery_info: %s", discovery_info)
|
||||
location = discovery_info[DISCOVERY_LOCATION]
|
||||
return await Device.async_create_device(hass, location)
|
||||
|
||||
@ -104,7 +107,7 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType):
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistantType, config_entry: ConfigEntry) -> bool:
|
||||
"""Set up UPnP/IGD device from a config entry."""
|
||||
_LOGGER.debug("async_setup_entry, config_entry: %s", config_entry.data)
|
||||
_LOGGER.debug("Setting up config entry: %s", config_entry.unique_id)
|
||||
|
||||
# Discover and construct.
|
||||
udn = config_entry.data.get(CONFIG_ENTRY_UDN)
|
||||
@ -123,6 +126,11 @@ async def async_setup_entry(hass: HomeAssistantType, config_entry: ConfigEntry)
|
||||
|
||||
# Ensure entry has a unique_id.
|
||||
if not config_entry.unique_id:
|
||||
_LOGGER.debug(
|
||||
"Setting unique_id: %s, for config_entry: %s",
|
||||
device.unique_id,
|
||||
config_entry,
|
||||
)
|
||||
hass.config_entries.async_update_entry(
|
||||
entry=config_entry,
|
||||
unique_id=device.unique_id,
|
||||
@ -152,6 +160,8 @@ async def async_unload_entry(
|
||||
hass: HomeAssistantType, config_entry: ConfigEntry
|
||||
) -> bool:
|
||||
"""Unload a UPnP/IGD device from a config entry."""
|
||||
_LOGGER.debug("Unloading config entry: %s", config_entry.unique_id)
|
||||
|
||||
udn = config_entry.data.get(CONFIG_ENTRY_UDN)
|
||||
if udn in hass.data[DOMAIN][DOMAIN_DEVICES]:
|
||||
del hass.data[DOMAIN][DOMAIN_DEVICES][udn]
|
||||
|
@ -154,6 +154,7 @@ class UpnpFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
self._abort_if_unique_id_configured()
|
||||
|
||||
# Store discovery.
|
||||
_LOGGER.debug("New discovery, continuing")
|
||||
name = discovery_info.get("friendlyName", "")
|
||||
discovery = {
|
||||
DISCOVERY_UDN: udn,
|
||||
|
@ -109,7 +109,7 @@ class Device:
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""Get string representation."""
|
||||
return f"IGD Device: {self.name}/{self.udn}"
|
||||
return f"IGD Device: {self.name}/{self.udn}::{self.device_type}"
|
||||
|
||||
async def async_get_traffic_data(self) -> Mapping[str, any]:
|
||||
"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user