From 308b7fb3854b05f716ee7e71cb757ed273b5bd9b Mon Sep 17 00:00:00 2001 From: Jason Hu Date: Wed, 12 Sep 2018 04:42:54 -0700 Subject: [PATCH] Add retry limit for chromecast connection (#16471) --- homeassistant/components/media_player/cast.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/media_player/cast.py b/homeassistant/components/media_player/cast.py index 83c3595ebd9c1e..beec1e5609cd4f 100644 --- a/homeassistant/components/media_player/cast.py +++ b/homeassistant/components/media_player/cast.py @@ -61,6 +61,10 @@ vol.All(cv.ensure_list, [cv.string]), }) +CONNECTION_RETRY = 3 +CONNECTION_RETRY_WAIT = 2 +CONNECTION_TIMEOUT = 10 + @attr.s(slots=True, frozen=True) class ChromecastInfo: @@ -368,15 +372,13 @@ async def async_set_cast_info(self, cast_info): return await self._async_disconnect() - # Failed connection will unfortunately never raise an exception, it - # will instead just try connecting indefinitely. # pylint: disable=protected-access _LOGGER.debug("Connecting to cast device %s", cast_info) chromecast = await self.hass.async_add_job( pychromecast._get_chromecast_from_host, ( cast_info.host, cast_info.port, cast_info.uuid, cast_info.model_name, cast_info.friendly_name - )) + ), CONNECTION_RETRY, CONNECTION_RETRY_WAIT, CONNECTION_TIMEOUT) self._chromecast = chromecast self._status_listener = CastStatusListener(self, chromecast) # Initialise connection status as connected because we can only