From df19d4fd155eb08646d92bf7ad7194a222526806 Mon Sep 17 00:00:00 2001 From: quthla Date: Thu, 20 Jul 2023 10:07:03 +0200 Subject: [PATCH] Ensure androidtv_remote does not block startup of HA (#96582) * Ensure androidtv_remote does not block startup of HA * Fix lint * Use asyncio.wait_for * Update homeassistant/components/androidtv_remote/__init__.py Co-authored-by: Erik Montnemery * Update homeassistant/components/androidtv_remote/__init__.py Co-authored-by: Erik Montnemery * Fix lint * Lint * Update __init__.py --------- Co-authored-by: Erik Montnemery --- homeassistant/components/androidtv_remote/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/androidtv_remote/__init__.py b/homeassistant/components/androidtv_remote/__init__.py index bdcf08bb2f6..9299b1ed0b0 100644 --- a/homeassistant/components/androidtv_remote/__init__.py +++ b/homeassistant/components/androidtv_remote/__init__.py @@ -1,6 +1,7 @@ """The Android TV Remote integration.""" from __future__ import annotations +import asyncio import logging from androidtvremote2 import ( @@ -9,6 +10,7 @@ from androidtvremote2 import ( ConnectionClosed, InvalidAuth, ) +import async_timeout from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_HOST, CONF_NAME, EVENT_HOMEASSISTANT_STOP, Platform @@ -43,11 +45,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: api.add_is_available_updated_callback(is_available_updated) try: - await api.async_connect() + async with async_timeout.timeout(5.0): + await api.async_connect() except InvalidAuth as exc: # The Android TV is hard reset or the certificate and key files were deleted. raise ConfigEntryAuthFailed from exc - except (CannotConnect, ConnectionClosed) as exc: + except (CannotConnect, ConnectionClosed, asyncio.TimeoutError) as exc: # The Android TV is network unreachable. Raise exception and let Home Assistant retry # later. If device gets a new IP address the zeroconf flow will update the config. raise ConfigEntryNotReady from exc