From 05960fa29c9c1059a05e37e8955823a3cf88df76 Mon Sep 17 00:00:00 2001 From: Steven Looman Date: Fri, 10 May 2019 01:17:47 +0200 Subject: [PATCH] Sort discovered entries by 'st' to ensure getting the same device each discovery (#23763) --- homeassistant/components/upnp/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/homeassistant/components/upnp/__init__.py b/homeassistant/components/upnp/__init__.py index 01f6d6159f0..fd2aa994ca4 100644 --- a/homeassistant/components/upnp/__init__.py +++ b/homeassistant/components/upnp/__init__.py @@ -1,5 +1,6 @@ """Open ports in your router for Home Assistant and provide statistics.""" from ipaddress import ip_address +from operator import itemgetter import voluptuous as vol @@ -88,6 +89,8 @@ async def async_discover_and_construct(hass, udn=None) -> Device: _LOGGER.warning('Wanted UPnP/IGD device with UDN "%s" not found, ' 'aborting', udn) return None + # ensure we're always taking the latest + filtered = sorted(filtered, key=itemgetter('st'), reverse=True) discovery_info = filtered[0] else: # get the first/any