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

Add additional keyword argument to set playlist to allow play control

This commit is contained in:
Nathan Spencer
2025-11-26 21:01:18 +00:00
parent 4336f658c4
commit fb360be616
2 changed files with 18 additions and 12 deletions

View File

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

View File

@@ -646,25 +646,32 @@ 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 devices 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 = [playlist] if start_playing is None:
start_playing = self.status_code == STATUS_PLAYING and len(playlist) > 0
client = self._require_client() client = self._require_client()
was_playing = self.status_code == STATUS_PLAYING await client.async_send_stop_command(self) # needed before replacing playlist
# 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) 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) 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: