forked from platypush/platypush
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:
parent
cabc154252
commit
65bac0ccc5
1 changed files with 12 additions and 4 deletions
|
@ -123,6 +123,14 @@ class MediaChromecastPlugin(MediaPlugin):
|
||||||
self.chromecasts = {}
|
self.chromecasts = {}
|
||||||
self._media_listeners = {}
|
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
|
@action
|
||||||
def get_chromecasts(self, tries=2, retry_wait=10, timeout=60,
|
def get_chromecasts(self, tries=2, retry_wait=10, timeout=60,
|
||||||
blocking=True, callback=None):
|
blocking=True, callback=None):
|
||||||
|
@ -151,7 +159,7 @@ class MediaChromecastPlugin(MediaPlugin):
|
||||||
import pychromecast
|
import pychromecast
|
||||||
self.chromecasts.update({
|
self.chromecasts.update({
|
||||||
cast.device.friendly_name: cast
|
cast.device.friendly_name: cast
|
||||||
for cast in pychromecast.get_chromecasts(tries=tries, retry_wait=retry_wait,
|
for cast in self._get_chromecasts(tries=tries, retry_wait=retry_wait,
|
||||||
timeout=timeout, blocking=blocking,
|
timeout=timeout, blocking=blocking,
|
||||||
callback=callback)
|
callback=callback)
|
||||||
})
|
})
|
||||||
|
@ -206,7 +214,7 @@ class MediaChromecastPlugin(MediaPlugin):
|
||||||
n_tries -= 1
|
n_tries -= 1
|
||||||
casts.update({
|
casts.update({
|
||||||
cast.device.friendly_name: cast
|
cast.device.friendly_name: cast
|
||||||
for cast in pychromecast.get_chromecasts()
|
for cast in self._get_chromecasts()
|
||||||
})
|
})
|
||||||
|
|
||||||
if chromecast in casts:
|
if chromecast in casts:
|
||||||
|
|
Loading…
Reference in a new issue