Skip to content

Commit

Permalink
Ensure androidtv_remote does not block startup of HA (#96582)
Browse files Browse the repository at this point in the history
* 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 <erik@montnemery.com>

* Update homeassistant/components/androidtv_remote/__init__.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Fix lint

* Lint

* Update __init__.py

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
  • Loading branch information
quthla and emontnemery committed Jul 20, 2023
1 parent 5ffffd8 commit df19d4f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions 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 (
Expand All @@ -9,6 +10,7 @@
ConnectionClosed,
InvalidAuth,
)
import async_timeout

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, CONF_NAME, EVENT_HOMEASSISTANT_STOP, Platform
Expand Down Expand Up @@ -43,11 +45,12 @@ def is_available_updated(is_available: bool) -> None:
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
Expand Down

0 comments on commit df19d4f

Please sign in to comment.