Skip to content

Commit

Permalink
Avoid playing queue pollution when restoring Sonos snapshots (#21963)
Browse files Browse the repository at this point in the history
Assume a snapshot state with three speakers in two groups, AB and C. They will
be playing the A and C queues, respectively. The B queue exists but is hidden
in this topology.

Unjoin B and form a new group BC, playing the B queue (now with the C queue
hidden).

To restore the snapshot we would join B back to A. The BC group would now only
contain the C speaker, still playing the B queue. The C queue has been lost :-(

The problem is that unjoining a coordinator will elect a new coordinator that
inherits the group queue and thus has its hidden queue overwritten.

This commit avoids the situation by having restore unjoin all slaves. Above, C
would be unjoined before joining B to A. This restores the C queue and since B
is then alone, it can be joined to A without having to transfer its playing
queue to remaining speakers.
  • Loading branch information
amelchio authored and pvizeli committed Mar 12, 2019
1 parent 2225425 commit dd11f8d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion homeassistant/components/sonos/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,8 +1037,13 @@ def restore_multi(entities, with_group):
if entity.state == STATE_PLAYING:
entity.media_pause()

# Bring back the original group topology
if with_group:
# Unjoin slaves that are not already in their target group
for entity in [e for e in entities if not e.is_coordinator]:
if entity._snapshot_group != entity._sonos_group:
entity.unjoin()

# Bring back the original group topology
for entity in (e for e in entities if e._snapshot_group):
if entity._snapshot_group[0] == entity:
entity.join(entity._snapshot_group)
Expand Down

0 comments on commit dd11f8d

Please sign in to comment.