From e6e4396e49d2b687b4ca4e9fa7b8196fd3c3108a Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 10 Dec 2023 21:50:53 +0100 Subject: [PATCH] Enhanced `get_default_media_plugin` to filter by video/audio plugins. --- platypush/entities/alarm.py | 1 + platypush/utils/media.py | 30 +++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/platypush/entities/alarm.py b/platypush/entities/alarm.py index fe68ed0d7..6a93c3345 100644 --- a/platypush/entities/alarm.py +++ b/platypush/entities/alarm.py @@ -28,6 +28,7 @@ if not is_defined('alarm'): snooze_interval = Column(Integer, nullable=True) actions = Column(JSON, nullable=True) static = Column(Boolean, nullable=False, default=False) + condition_type = Column(String, nullable=False) __table_args__ = {'extend_existing': True} __mapper_args__ = { diff --git a/platypush/utils/media.py b/platypush/utils/media.py index 2a6cde1e7..bc1d8749b 100644 --- a/platypush/utils/media.py +++ b/platypush/utils/media.py @@ -5,9 +5,17 @@ from platypush.context import get_plugin from platypush.plugins.media import MediaPlugin -def get_default_media_plugin() -> MediaPlugin: +audio_plugins = [ + 'sound', + 'music.mpd', +] + + +def get_default_media_plugin(video: bool = False) -> MediaPlugin: """ Get the default media plugin based on the current configuration. + + :param video: If True then the plugin must support video playback. """ enabled_plugins: List[MediaPlugin] = [] @@ -26,8 +34,20 @@ def get_default_media_plugin() -> MediaPlugin: if local_plugins: return local_plugins[0] - assert ( - enabled_plugins - ), f'No media plugin is enabled. Supported plugins: {MediaPlugin.supported_media_plugins}' + if enabled_plugins: + return enabled_plugins[0] - return enabled_plugins[0] + assert not video, ( + 'No media plugin with video support is enabled. ' + f'Supported plugins: {MediaPlugin.supported_media_plugins}' + ) + + for plugin_name in audio_plugins: + try: + plugin = get_plugin(plugin_name) + if plugin and plugin_name in cfg and not cfg[plugin_name].get('disabled'): + return plugin + except Exception: + pass + + raise AssertionError('No media plugin is enabled')