Improve repeat and shuffle support for Squeezebox (#70941)

This commit is contained in:
Raj Laud 2022-04-28 04:35:04 -04:00 committed by GitHub
parent 573e966d74
commit 0264f060e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,6 +20,9 @@ from homeassistant.components.media_player.const import (
ATTR_MEDIA_ENQUEUE,
MEDIA_TYPE_MUSIC,
MEDIA_TYPE_PLAYLIST,
REPEAT_MODE_ALL,
REPEAT_MODE_OFF,
REPEAT_MODE_ONE,
)
from homeassistant.config_entries import SOURCE_INTEGRATION_DISCOVERY, ConfigEntry
from homeassistant.const import (
@ -231,6 +234,7 @@ class SqueezeBoxEntity(MediaPlayerEntity):
| MediaPlayerEntityFeature.TURN_OFF
| MediaPlayerEntityFeature.PLAY_MEDIA
| MediaPlayerEntityFeature.PLAY
| MediaPlayerEntityFeature.REPEAT_SET
| MediaPlayerEntityFeature.SHUFFLE_SET
| MediaPlayerEntityFeature.CLEAR_PLAYLIST
| MediaPlayerEntityFeature.STOP
@ -373,10 +377,20 @@ class SqueezeBoxEntity(MediaPlayerEntity):
"""Album of current playing media."""
return self._player.album
@property
def repeat(self):
"""Repeat setting."""
if self._player.repeat == "song":
return REPEAT_MODE_ONE
if self._player.repeat == "playlist":
return REPEAT_MODE_ALL
return REPEAT_MODE_OFF
@property
def shuffle(self):
"""Boolean if shuffle is enabled."""
return self._player.shuffle
# Squeezebox has a third shuffle mode (album) not recognized by Home Assistant
return self._player.shuffle == "song"
@property
def sync_group(self):
@ -499,6 +513,17 @@ class SqueezeBoxEntity(MediaPlayerEntity):
if index is not None:
await self._player.async_index(index)
async def async_set_repeat(self, repeat):
"""Set the repeat mode."""
if repeat == REPEAT_MODE_ALL:
repeat_mode = "playlist"
elif repeat == REPEAT_MODE_ONE:
repeat_mode = "song"
else:
repeat_mode = "none"
await self._player.async_set_repeat(repeat_mode)
async def async_set_shuffle(self, shuffle):
"""Enable/disable shuffle mode."""
shuffle_mode = "song" if shuffle else "none"