Skip to content

Commit

Permalink
Fix: Enqueue player feature not correctly set on cast groups and dlna…
Browse files Browse the repository at this point in the history
… players
  • Loading branch information
marcelveldt committed Oct 28, 2024
1 parent 16704be commit f9a855d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
12 changes: 8 additions & 4 deletions music_assistant/server/controllers/players.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,10 +571,14 @@ async def play_media(self, player_id: str, media: PlayerMedia) -> None:

async def enqueue_next_media(self, player_id: str, media: PlayerMedia) -> None:
"""Handle enqueuing of a next media item on the player."""
if (player := self.get(player_id)) and PlayerFeature.ENQUEUE in player.supported_features:
player_prov = self.mass.get_provider(player.provider)
async with self._player_throttlers[player_id]:
await player_prov.enqueue_next_media(player_id=player_id, media=media)
player = self.get(player_id, raise_unavailable=True)
if PlayerFeature.ENQUEUE not in player.supported_features:
raise UnsupportedFeaturedException(
f"Player {player.display_name} does not support enqueueing"
)
player_prov = self.mass.get_provider(player.provider)
async with self._player_throttlers[player_id]:
await player_prov.enqueue_next_media(player_id=player_id, media=media)

@api_command("players/cmd/sync")
@handle_player_command
Expand Down
1 change: 1 addition & 0 deletions music_assistant/server/providers/chromecast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ def on_new_cast_status(self, castplayer: CastPlayer, status: CastStatus) -> None
PlayerFeature.POWER,
PlayerFeature.VOLUME_SET,
PlayerFeature.PAUSE,
PlayerFeature.ENQUEUE,
)

# update player status
Expand Down
33 changes: 11 additions & 22 deletions music_assistant/server/providers/dlna/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@
from music_assistant.server import MusicAssistant
from music_assistant.server.models import ProviderInstanceType

BASE_PLAYER_FEATURES = (PlayerFeature.VOLUME_MUTE, PlayerFeature.VOLUME_SET)


PLAYER_CONFIG_ENTRIES = (
CONF_ENTRY_CROSSFADE_FLOW_MODE_REQUIRED,
Expand Down Expand Up @@ -179,7 +177,6 @@ def update_attributes(self) -> None:
self.player.volume_level = int((self.device.volume_level or 0) * 100)
self.player.volume_muted = self.device.is_volume_muted or False
self.player.state = self.get_state(self.device)
self.player.supported_features = self.get_supported_features(self.device)
self.player.current_item_id = self.device.current_track_uri or ""
if self.player.player_id in self.player.current_item_id:
self.player.active_source = self.player.player_id
Expand Down Expand Up @@ -227,21 +224,6 @@ def get_state(device: DmrDevice) -> PlayerState:

return PlayerState.IDLE

@staticmethod
def get_supported_features(device: DmrDevice) -> set[PlayerFeature]:
"""Get player features that are supported at this moment.
Supported features may change as the device enters different states.
"""
supported_features = set()

if device.has_volume_level:
supported_features.add(PlayerFeature.VOLUME_SET)
if device.has_volume_mute:
supported_features.add(PlayerFeature.VOLUME_MUTE)

return supported_features


class DLNAPlayerProvider(PlayerProvider):
"""DLNA Player provider."""
Expand Down Expand Up @@ -619,11 +601,18 @@ async def _update_player(self, dlna_player: DLNAPlayer) -> None:

def _set_player_features(self, dlna_player: DLNAPlayer) -> None:
"""Set Player Features based on config values and capabilities."""
if self.mass.config.get_raw_player_config_value(
supported_features: set[PlayerFeature] = set()
if not self.mass.config.get_raw_player_config_value(
dlna_player.udn,
CONF_ENTRY_FLOW_MODE_DEFAULT_ENABLED.key,
CONF_ENTRY_FLOW_MODE_DEFAULT_ENABLED.default_value,
):
dlna_player.player.supported_features = BASE_PLAYER_FEATURES
else:
dlna_player.player.supported_features = (*BASE_PLAYER_FEATURES, PlayerFeature.ENQUEUE)
supported_features.add(PlayerFeature.ENQUEUE)

if dlna_player.device.has_volume_level:
supported_features.add(PlayerFeature.VOLUME_SET)
if dlna_player.device.has_volume_mute:
supported_features.add(PlayerFeature.VOLUME_MUTE)
if dlna_player.device.has_pause:
supported_features.add(PlayerFeature.PAUSE)
dlna_player.player.supported_features = tuple(supported_features)

0 comments on commit f9a855d

Please sign in to comment.