diff --git a/homeassistant/components/hue/bridge.py b/homeassistant/components/hue/bridge.py index abf91cf4577..86db9c4021c 100644 --- a/homeassistant/components/hue/bridge.py +++ b/homeassistant/components/hue/bridge.py @@ -71,10 +71,11 @@ class HueBridge: async def async_initialize_bridge(self) -> bool: """Initialize Connection with the Hue API.""" + setup_ok = False try: async with asyncio.timeout(10): await self.api.initialize() - + setup_ok = True except (LinkButtonNotPressed, Unauthorized): # Usernames can become invalid if hub is reset or user removed. # We are going to fail the config entry setup and initiate a new @@ -95,6 +96,9 @@ class HueBridge: except Exception: # pylint: disable=broad-except self.logger.exception("Unknown error connecting to Hue bridge") return False + finally: + if not setup_ok: + await self.api.close() # v1 specific initialization/setup code here if self.api_version == 1: