Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
[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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just saw this PR while working through my mailbox. Before a chromecast rewrite it was done like with your new code. However, the problem with this change is that if the retry limit is exceeded (for example by plugging the CC out for a while), hass will no longer attempt to reconnect.

Anyway, I guess the only way to get rid of all these CC issues is to make pychromecast a bit more async aware. Either by converting it to asyncio (lots of work, trust me I tried) or by making use of the blocking parameter.

self._chromecast = chromecast
self._status_listener = CastStatusListener(self, chromecast)
# Initialise connection status as connected because we can only
Expand Down