From fb360be616aab2d068d5a68b9ce02aed92f65cf9 Mon Sep 17 00:00:00 2001 From: Nathan Spencer Date: Wed, 26 Nov 2025 21:01:18 +0000 Subject: [PATCH] Add additional keyword argument to set playlist to allow play control --- custom_components/oasis_mini/media_player.py | 3 +-- .../oasis_mini/pyoasiscontrol/device.py | 27 ++++++++++++------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/custom_components/oasis_mini/media_player.py b/custom_components/oasis_mini/media_player.py index 1e5cd73..0b163e4 100644 --- a/custom_components/oasis_mini/media_player.py +++ b/custom_components/oasis_mini/media_player.py @@ -340,8 +340,7 @@ class OasisDeviceMediaPlayerEntity(OasisDeviceEntity, MediaPlayerEntity): return if enqueue == MediaPlayerEnqueue.REPLACE: - await device.async_set_playlist(track_ids) - await device.async_play() + await device.async_set_playlist(track_ids, start_playing=True) return insert_at = (device.playlist_index or 0) + 1 diff --git a/custom_components/oasis_mini/pyoasiscontrol/device.py b/custom_components/oasis_mini/pyoasiscontrol/device.py index 67c0fbb..73ebba9 100644 --- a/custom_components/oasis_mini/pyoasiscontrol/device.py +++ b/custom_components/oasis_mini/pyoasiscontrol/device.py @@ -646,25 +646,32 @@ class OasisDevice: client = self._require_client() await client.async_send_add_joblist_command(self, tracks) - async def async_set_playlist(self, playlist: int | Iterable[int]) -> None: + async def async_set_playlist( + self, playlist: int | Iterable[int], *, start_playing: bool | None = None + ) -> None: """ Set the device's playlist to the provided track or tracks. - Accepts a single track ID or an iterable of track IDs and replaces the device's playlist by sending the corresponding command to the attached client. + Accepts a single track ID or an iterable of track IDs, stops the device, + replaces the playlist, and resumes playback based on the `start_playing` + parameter or, if unspecified, the device’s prior playing state. Parameters: - playlist (int | Iterable[int]): A single track ID or an iterable of track IDs to set as the new playlist. + playlist (int | Iterable[int]): + A single track ID or an iterable of track IDs to set as the new playlist. + start_playing (bool | None, keyword-only): + Whether to start playback after updating the playlist. If None (default), + playback will resume only if the device was previously playing and the + new playlist is non-empty. """ - if isinstance(playlist, int): - playlist = [playlist] + playlist = [playlist] if isinstance(playlist, int) else list(playlist) + if start_playing is None: + start_playing = self.status_code == STATUS_PLAYING and len(playlist) > 0 client = self._require_client() - was_playing = self.status_code == STATUS_PLAYING - - # We need to stop the device so we can set the full playlist - await client.async_send_stop_command(self) + await client.async_send_stop_command(self) # needed before replacing playlist await client.async_send_set_playlist_command(self, playlist) - if was_playing and len(playlist) > 0: + if start_playing: await client.async_send_play_command(self) async def async_set_repeat_playlist(self, repeat: bool) -> None: