Fix for pychromecast.get_chromecasts new return type.

On newer versions of pychromecast get_chromecasts returns
a tuple (devices, browser_service) instead of a list. The
software should be robust enough with both older and newer
versions of pychromecast.
This commit is contained in:
Fabio Manganiello 2020-07-25 01:35:06 +02:00
parent cabc154252
commit 65bac0ccc5

View file

@ -123,6 +123,14 @@ class MediaChromecastPlugin(MediaPlugin):
self.chromecasts = {}
self._media_listeners = {}
@staticmethod
def _get_chromecasts(*args, **kwargs):
import pychromecast
chromecasts = pychromecast.get_chromecasts(*args, **kwargs)
if isinstance(chromecasts, tuple):
return chromecasts[0]
return chromecasts
@action
def get_chromecasts(self, tries=2, retry_wait=10, timeout=60,
blocking=True, callback=None):
@ -151,9 +159,9 @@ class MediaChromecastPlugin(MediaPlugin):
import pychromecast
self.chromecasts.update({
cast.device.friendly_name: cast
for cast in pychromecast.get_chromecasts(tries=tries, retry_wait=retry_wait,
timeout=timeout, blocking=blocking,
callback=callback)
for cast in self._get_chromecasts(tries=tries, retry_wait=retry_wait,
timeout=timeout, blocking=blocking,
callback=callback)
})
for name, cast in self.chromecasts.items():
@ -206,7 +214,7 @@ class MediaChromecastPlugin(MediaPlugin):
n_tries -= 1
casts.update({
cast.device.friendly_name: cast
for cast in pychromecast.get_chromecasts()
for cast in self._get_chromecasts()
})
if chromecast in casts: