From ba9c969d91c5f32561b9a07a91a48387fec624d1 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 23 Aug 2023 10:21:38 -0500 Subject: [PATCH] Retry lookin setup later if the wrong device is found (#98881) --- homeassistant/components/lookin/__init__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/homeassistant/components/lookin/__init__.py b/homeassistant/components/lookin/__init__.py index c16d7f34f0f..7656de8d385 100644 --- a/homeassistant/components/lookin/__init__.py +++ b/homeassistant/components/lookin/__init__.py @@ -104,6 +104,17 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: except (asyncio.TimeoutError, aiohttp.ClientError, NoUsableService) as ex: raise ConfigEntryNotReady from ex + if entry.unique_id != (found_uuid := lookin_device.id.upper()): + # If the uuid of the device does not match the unique_id + # of the config entry, it likely means the DHCP lease has expired + # and the device has been assigned a new IP address. We need to + # wait for the next discovery to find the device at its new address + # and update the config entry so we do not mix up devices. + raise ConfigEntryNotReady( + f"Unexpected device found at {host}; expected {entry.unique_id}, " + f"found {found_uuid}" + ) + push_coordinator = LookinPushCoordinator(entry.title) if lookin_device.model >= 2: