From 65bac0ccc57a60d3b71ac75c37fceb822a07e3cd Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sat, 25 Jul 2020 01:35:06 +0200 Subject: [PATCH] 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. --- platypush/plugins/media/chromecast.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/platypush/plugins/media/chromecast.py b/platypush/plugins/media/chromecast.py index f079d1fc6..48c152c9d 100644 --- a/platypush/plugins/media/chromecast.py +++ b/platypush/plugins/media/chromecast.py @@ -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: