From 9add8890cd1fca7739b43a6c297e23907b5b8ed5 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Tue, 5 Feb 2019 09:49:50 +0100 Subject: [PATCH] Support for complete Chromecasts status --- platypush/plugins/media/__init__.py | 2 +- platypush/plugins/media/chromecast.py | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/platypush/plugins/media/__init__.py b/platypush/plugins/media/__init__.py index 77ce7fede..617baca50 100644 --- a/platypush/plugins/media/__init__.py +++ b/platypush/plugins/media/__init__.py @@ -134,7 +134,7 @@ class MediaPlugin(Plugin): if resource.startswith('youtube:') \ or resource.startswith('https://www.youtube.com/watch?v='): - if self.__class.__.__name__ != 'MediaChromecastPlugin': + if self.__class__.__name__ == 'MediaChromecastPlugin': # The Chromecast has already its way to handle YouTube return resource diff --git a/platypush/plugins/media/chromecast.py b/platypush/plugins/media/chromecast.py index f30be42f0..bd38b8782 100644 --- a/platypush/plugins/media/chromecast.py +++ b/platypush/plugins/media/chromecast.py @@ -266,6 +266,11 @@ class MediaChromecastPlugin(MediaPlugin): return self.get_chromecast(chromecast or self.chromecast).media_controller.is_paused + @action + def is_idle(self, chromecast=None): + return self.get_chromecast(chromecast or self.chromecast).media_controller.is_idle + + @action def enable_subtitle(self, chromecast=None): return self.get_chromecast(chromecast or self.chromecast).media_controller.enable_subtitle() @@ -278,7 +283,24 @@ class MediaChromecastPlugin(MediaPlugin): @action def status(self, chromecast=None): - return self.get_chromecast(chromecast or self.chromecast).media_controller.status + status = self.get_chromecast(chromecast or self.chromecast) \ + .media_controller.status + attrs = [a for a in dir(status) if not a.startswith('_') + and not callable(getattr(status, a))] + renamed_attrs = { + 'player_state': 'state', + 'volume_level': 'volume', + 'volume_muted': 'muted', + } + + ret = {} + for attr in attrs: + if attr in renamed_attrs: + ret[renamed_attrs[attr]] = getattr(status, attr) + else: + ret[attr] = getattr(status, attr) + + return ret @action