From 4336f658c4df5d46dff7030f7680ad86cd68b1ee Mon Sep 17 00:00:00 2001 From: Nathan Spencer Date: Wed, 26 Nov 2025 20:32:12 +0000 Subject: [PATCH] Make device own required steps when setting playlist --- custom_components/oasis_mini/media_player.py | 1 - .../oasis_mini/pyoasiscontrol/device.py | 14 ++++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/custom_components/oasis_mini/media_player.py b/custom_components/oasis_mini/media_player.py index 92bc306..1e5cd73 100644 --- a/custom_components/oasis_mini/media_player.py +++ b/custom_components/oasis_mini/media_player.py @@ -340,7 +340,6 @@ class OasisDeviceMediaPlayerEntity(OasisDeviceEntity, MediaPlayerEntity): return if enqueue == MediaPlayerEnqueue.REPLACE: - await device.async_stop() await device.async_set_playlist(track_ids) await device.async_play() return diff --git a/custom_components/oasis_mini/pyoasiscontrol/device.py b/custom_components/oasis_mini/pyoasiscontrol/device.py index bb02fde..67c0fbb 100644 --- a/custom_components/oasis_mini/pyoasiscontrol/device.py +++ b/custom_components/oasis_mini/pyoasiscontrol/device.py @@ -11,6 +11,7 @@ from .const import ( LED_EFFECTS, STATUS_CODE_MAP, STATUS_ERROR, + STATUS_PLAYING, STATUS_SLEEPING, TRACKS, ) @@ -655,11 +656,16 @@ class OasisDevice: playlist (int | Iterable[int]): A single track ID or an iterable of track IDs to set as the new playlist. """ if isinstance(playlist, int): - playlist_list = [playlist] - else: - playlist_list = list(playlist) + playlist = [playlist] + client = self._require_client() - await client.async_send_set_playlist_command(self, playlist_list) + 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_set_playlist_command(self, playlist) + if was_playing and len(playlist) > 0: + await client.async_send_play_command(self) async def async_set_repeat_playlist(self, repeat: bool) -> None: """