Improve lutron caseta error reporting when bridge is offline (#57832)

This commit is contained in:
J. Nick Koston 2021-10-16 23:11:35 -10:00 committed by GitHub
parent f4918b2d9a
commit 378c48da15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)