From 378c48da15720da937a19b072dc53685dd271e6f Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 16 Oct 2021 23:11:35 -1000 Subject: [PATCH] Improve lutron caseta error reporting when bridge is offline (#57832) --- homeassistant/components/lutron_caseta/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/lutron_caseta/__init__.py b/homeassistant/components/lutron_caseta/__init__.py index 144a9a74c55..44e6e8761b1 100644 --- a/homeassistant/components/lutron_caseta/__init__.py +++ b/homeassistant/components/lutron_caseta/__init__.py @@ -1,5 +1,6 @@ """Component for interacting with a Lutron Caseta system.""" import asyncio +import contextlib import logging import ssl @@ -106,16 +107,17 @@ async def async_setup_entry(hass, config_entry): return False timed_out = True - try: + with contextlib.suppress(asyncio.TimeoutError): async with async_timeout.timeout(BRIDGE_TIMEOUT): await bridge.connect() timed_out = False - except asyncio.TimeoutError: - _LOGGER.error("Timeout while trying to connect to bridge at %s", host) if timed_out or not bridge.is_connected(): await bridge.close() - raise ConfigEntryNotReady + if timed_out: + raise ConfigEntryNotReady(f"Timed out while trying to connect to {host}") + if not bridge.is_connected(): + raise ConfigEntryNotReady(f"Cannot connect to {host}") _LOGGER.debug("Connected to Lutron Caseta bridge via LEAP at %s", host)