1
0
mirror of https://github.com/natekspencer/hacs-oasis_mini.git synced 2025-12-06 18:44:14 -05:00

Merge pull request #109 from natekspencer/set-playlist

Make device own required steps when setting playlist
This commit is contained in:
Nathan Spencer
2025-11-26 14:52:24 -07:00
committed by GitHub
2 changed files with 22 additions and 11 deletions

View File

@@ -340,9 +340,7 @@ class OasisDeviceMediaPlayerEntity(OasisDeviceEntity, MediaPlayerEntity):
return return
if enqueue == MediaPlayerEnqueue.REPLACE: if enqueue == MediaPlayerEnqueue.REPLACE:
await device.async_stop() await device.async_set_playlist(track_ids, start_playing=True)
await device.async_set_playlist(track_ids)
await device.async_play()
return return
insert_at = (device.playlist_index or 0) + 1 insert_at = (device.playlist_index or 0) + 1

View File

@@ -11,6 +11,7 @@ from .const import (
LED_EFFECTS, LED_EFFECTS,
STATUS_CODE_MAP, STATUS_CODE_MAP,
STATUS_ERROR, STATUS_ERROR,
STATUS_PLAYING,
STATUS_SLEEPING, STATUS_SLEEPING,
TRACKS, TRACKS,
) )
@@ -645,21 +646,33 @@ class OasisDevice:
client = self._require_client() client = self._require_client()
await client.async_send_add_joblist_command(self, tracks) 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. 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: 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] if isinstance(playlist, int) else list(playlist)
playlist_list = [playlist] if start_playing is None:
else: start_playing = self.status_code == STATUS_PLAYING
playlist_list = list(playlist)
client = self._require_client() client = self._require_client()
await client.async_send_set_playlist_command(self, playlist_list) await client.async_send_stop_command(self) # needed before replacing playlist
await client.async_send_set_playlist_command(self, playlist)
if start_playing and playlist:
await client.async_send_play_command(self)
async def async_set_repeat_playlist(self, repeat: bool) -> None: async def async_set_repeat_playlist(self, repeat: bool) -> None:
""" """