From 3e26e2adad9fc077ddf63d7b254c324cff3c5cb2 Mon Sep 17 00:00:00 2001 From: Steven Looman Date: Wed, 24 Feb 2021 04:00:47 +0100 Subject: [PATCH] Handle device IP change in upnp (#46859) --- homeassistant/components/upnp/__init__.py | 5 ++++- homeassistant/components/upnp/config_flow.py | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/upnp/__init__.py b/homeassistant/components/upnp/__init__.py index 5d251ce7dd8..d5be0757cf3 100644 --- a/homeassistant/components/upnp/__init__.py +++ b/homeassistant/components/upnp/__init__.py @@ -123,7 +123,10 @@ async def async_setup_entry(hass: HomeAssistantType, config_entry: ConfigEntry) ) # Ensure entry has a hostname, for older entries. - if CONFIG_ENTRY_HOSTNAME not in config_entry.data: + if ( + CONFIG_ENTRY_HOSTNAME not in config_entry.data + or config_entry.data[CONFIG_ENTRY_HOSTNAME] != device.hostname + ): hass.config_entries.async_update_entry( entry=config_entry, data={CONFIG_ENTRY_HOSTNAME: device.hostname, **config_entry.data}, diff --git a/homeassistant/components/upnp/config_flow.py b/homeassistant/components/upnp/config_flow.py index 1d212441bfa..e1101c3713c 100644 --- a/homeassistant/components/upnp/config_flow.py +++ b/homeassistant/components/upnp/config_flow.py @@ -179,7 +179,9 @@ class UpnpFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): discovery = await Device.async_supplement_discovery(self.hass, discovery) unique_id = discovery[DISCOVERY_UNIQUE_ID] await self.async_set_unique_id(unique_id) - self._abort_if_unique_id_configured() + self._abort_if_unique_id_configured( + updates={CONFIG_ENTRY_HOSTNAME: discovery[DISCOVERY_HOSTNAME]} + ) # Handle devices changing their UDN, only allow a single existing_entries = self.hass.config_entries.async_entries(DOMAIN)