From 2b4218f8f9ba7b43a509058281d9ff7c97181dd0 Mon Sep 17 00:00:00 2001 From: SiemonG Date: Sun, 1 Dec 2024 01:35:11 +0100 Subject: [PATCH 1/2] adding continuous parameter and resolving bug in resuming playQueue adding continuous parameter and resolving bug in resuming playQueue accept true or 1 as value ruff changes --- homeassistant/components/plex/models.py | 7 ++++++- homeassistant/components/plex/services.py | 8 ++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/plex/models.py b/homeassistant/components/plex/models.py index f2fa3f60d242f..bdc3ca197f06e 100644 --- a/homeassistant/components/plex/models.py +++ b/homeassistant/components/plex/models.py @@ -2,6 +2,8 @@ import logging +import plexapi.playqueue + from homeassistant.components.media_player import MediaType from homeassistant.helpers.template import result_as_boolean from homeassistant.util import dt as dt_util @@ -167,7 +169,10 @@ def offset(self) -> int: if isinstance(resume, str): resume = result_as_boolean(resume) if resume: - return self.media.viewOffset + media = self.media + if isinstance(media, plexapi.playqueue.PlayQueue) and len(media.items) > 0: + media = media.items[0] + return getattr(media, "viewOffset", 0) return 0 @property diff --git a/homeassistant/components/plex/services.py b/homeassistant/components/plex/services.py index c70ddb6ed53cf..b6698081966df 100644 --- a/homeassistant/components/plex/services.py +++ b/homeassistant/components/plex/services.py @@ -193,6 +193,7 @@ def process_plex_payload( search_query = content.copy() shuffle = search_query.pop("shuffle", 0) + continuous = search_query.pop("continuous", 0) # Remove internal kwargs before passing copy to plexapi for internal_key in ("resume", "offset"): @@ -200,9 +201,12 @@ def process_plex_payload( media = plex_server.lookup_media(content_type, **search_query) - if supports_playqueues and (isinstance(media, list) or shuffle): + if supports_playqueues and (isinstance(media, list) or shuffle or continuous): playqueue = plex_server.create_playqueue( - media, includeRelated=0, shuffle=shuffle + media, + includeRelated=0, + shuffle=1 if shuffle else 0, + continuous=1 if continuous else 0 ) return PlexMediaSearchResult(playqueue, content) From f66daf9568d1312ad75a90bd8286e54d8f59ca90 Mon Sep 17 00:00:00 2001 From: SiemonG Date: Sun, 1 Dec 2024 01:38:19 +0100 Subject: [PATCH 2/2] Ruff changes --- homeassistant/components/plex/services.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/plex/services.py b/homeassistant/components/plex/services.py index b6698081966df..923fbe3bd5387 100644 --- a/homeassistant/components/plex/services.py +++ b/homeassistant/components/plex/services.py @@ -205,8 +205,8 @@ def process_plex_payload( playqueue = plex_server.create_playqueue( media, includeRelated=0, - shuffle=1 if shuffle else 0, - continuous=1 if continuous else 0 + shuffle=1 if shuffle else 0, + continuous=1 if continuous else 0, ) return PlexMediaSearchResult(playqueue, content)