From 5f8fcca5adfb5ba3a710ac3b1f76b42a4c7f2103 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 6 Apr 2021 21:39:04 -1000 Subject: [PATCH] Solve cast delaying startup when discovered devices are slow to setup (#48755) * Solve cast delaying startup when devices are slow to setup * Update homeassistant/components/cast/media_player.py Co-authored-by: Erik Montnemery Co-authored-by: Erik Montnemery --- homeassistant/components/cast/media_player.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/cast/media_player.py b/homeassistant/components/cast/media_player.py index 7c2a696027f..25b2674821d 100644 --- a/homeassistant/components/cast/media_player.py +++ b/homeassistant/components/cast/media_player.py @@ -1,6 +1,7 @@ """Provide functionality to interact with Cast devices on the network.""" from __future__ import annotations +import asyncio from contextlib import suppress from datetime import timedelta import functools as ft @@ -185,7 +186,9 @@ class CastDevice(MediaPlayerEntity): ) self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self._async_stop) self.async_set_cast_info(self._cast_info) - self.hass.async_create_task( + # asyncio.create_task is used to avoid delaying startup wrapup if the device + # is discovered already during startup but then fails to respond + asyncio.create_task( async_create_catching_coro(self.async_connect_to_chromecast()) )