Skip to content

Commit

Permalink
Add retry limit for chromecast connection (#16471)
Browse files Browse the repository at this point in the history
  • Loading branch information
awarecan authored and balloob committed Sep 12, 2018
1 parent 4efe863 commit 308b7fb
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions homeassistant/components/media_player/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 308b7fb

Please sign in to comment.