Skip to content

Commit

Permalink
Fix group state updating
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Oct 24, 2024
1 parent de39ee9 commit dbf7203
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
15 changes: 7 additions & 8 deletions music_assistant/server/controllers/players.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,6 @@ def update(
prev_state,
new_state,
ignore_keys=[
"elapsed_time",
"elapsed_time_last_updated",
"seq_no",
"last_poll",
Expand All @@ -848,13 +847,15 @@ def update(
# ignore updates for disabled players
return

# always signal update to the playerqueue
self.mass.player_queues.on_player_update(player, changed_values)

if len(changed_values) == 0 and not force_update:
return

self.mass.signal_event(EventType.PLAYER_UPDATED, object_id=player_id, data=player)
# signal update to the playerqueue
self.mass.player_queues.on_player_update(player, changed_values)

if changed_values != {"elapsed_time"} or force_update:
# ignore elapsed_time only changes
self.mass.signal_event(EventType.PLAYER_UPDATED, object_id=player_id, data=player)

if skip_forward and not force_update:
return
Expand Down Expand Up @@ -1226,9 +1227,7 @@ async def _poll_players(self) -> None:
player_id = player.player_id
# if the player is playing, update elapsed time every tick
# to ensure the queue has accurate details
player_playing = (
player.active_source == player.player_id and player.state == PlayerState.PLAYING
)
player_playing = player.state == PlayerState.PLAYING
if player_playing:
self.mass.loop.call_soon(self.update, player_id)
# Poll player;
Expand Down
9 changes: 1 addition & 8 deletions music_assistant/server/providers/player_group/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,13 +511,6 @@ async def poll_player(self, player_id: str) -> None:
if 'needs_poll' is set to True in the player object.
"""
if group_player := self.mass.players.get(player_id):
# dynamically change the poll interval
if group_player.state == PlayerState.PLAYING:
group_player.poll_interval = 5
elif group_player.powered:
group_player.poll_interval = 20
else:
group_player.poll_interval = 60
self._update_attributes(group_player)

async def create_group(self, group_type: str, name: str, members: list[str]) -> Player:
Expand Down Expand Up @@ -690,7 +683,7 @@ async def _register_group_player(
group_childs=set(members),
active_source=group_player_id,
needs_poll=True,
poll_interval=5,
poll_interval=30,
)

await self.mass.players.register_or_update(player)
Expand Down
5 changes: 2 additions & 3 deletions music_assistant/server/providers/slimproto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ async def _serve_multi_client_stream(self, request: web.Request) -> web.Response
fmt = request.query.get("fmt")
child_player_id = request.query.get("child_player_id")

if not (player := self.mass.players.get(player_id)):
if not self.mass.players.get(player_id):
raise web.HTTPNotFound(reason=f"Unknown player: {player_id}")

if not (child_player := self.mass.players.get(child_player_id)):
Expand All @@ -955,8 +955,7 @@ async def _serve_multi_client_stream(self, request: web.Request) -> web.Response

# all checks passed, start streaming!
self.logger.debug(
"Start serving multi-client flow audio stream for player %s to %s",
player.display_name,
"Start serving multi-client flow audio stream to %s",
child_player.display_name,
)

Expand Down

0 comments on commit dbf7203

Please sign in to comment.