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:
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user