From 8c41d0d3d712954eae142f84ae3b03730418537f Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 29 Aug 2022 04:02:41 -0500 Subject: [PATCH] Ensure LIFX connection is cleaned up on failure (#77465) Fixes #77464 --- homeassistant/components/lifx/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/lifx/__init__.py b/homeassistant/components/lifx/__init__.py index ec54382ec40..6af30b91d28 100644 --- a/homeassistant/components/lifx/__init__.py +++ b/homeassistant/components/lifx/__init__.py @@ -193,10 +193,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: try: await connection.async_setup() except socket.gaierror as ex: + connection.async_stop() raise ConfigEntryNotReady(f"Could not resolve {host}: {ex}") from ex coordinator = LIFXUpdateCoordinator(hass, connection, entry.title) coordinator.async_setup() - await coordinator.async_config_entry_first_refresh() + try: + await coordinator.async_config_entry_first_refresh() + except ConfigEntryNotReady: + connection.async_stop() + raise domain_data[entry.entry_id] = coordinator await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)