mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Fix Sonos shuffle/repeat state with Spotify Connect (#41939)
This commit is contained in:
parent
5580b21260
commit
30b454ddb7
@ -82,7 +82,7 @@ SERVICE_SELECT_SOURCE = "select_source"
|
|||||||
REPEAT_MODE_ALL = "all"
|
REPEAT_MODE_ALL = "all"
|
||||||
REPEAT_MODE_OFF = "off"
|
REPEAT_MODE_OFF = "off"
|
||||||
REPEAT_MODE_ONE = "one"
|
REPEAT_MODE_ONE = "one"
|
||||||
REPEAT_MODES = [REPEAT_MODE_ALL, REPEAT_MODE_OFF, REPEAT_MODE_ONE]
|
REPEAT_MODES = [REPEAT_MODE_OFF, REPEAT_MODE_ALL, REPEAT_MODE_ONE]
|
||||||
|
|
||||||
SUPPORT_PAUSE = 1
|
SUPPORT_PAUSE = 1
|
||||||
SUPPORT_SEEK = 2
|
SUPPORT_SEEK = 2
|
||||||
|
@ -9,6 +9,7 @@ import urllib.parse
|
|||||||
import async_timeout
|
import async_timeout
|
||||||
import pysonos
|
import pysonos
|
||||||
from pysonos import alarms
|
from pysonos import alarms
|
||||||
|
from pysonos.core import PLAY_MODE_BY_MEANING, PLAY_MODES
|
||||||
from pysonos.exceptions import SoCoException, SoCoUPnPException
|
from pysonos.exceptions import SoCoException, SoCoUPnPException
|
||||||
import pysonos.music_library
|
import pysonos.music_library
|
||||||
import pysonos.snapshot
|
import pysonos.snapshot
|
||||||
@ -197,6 +198,14 @@ PLAYABLE_MEDIA_TYPES = [
|
|||||||
MEDIA_TYPE_TRACK,
|
MEDIA_TYPE_TRACK,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
REPEAT_TO_SONOS = {
|
||||||
|
REPEAT_MODE_OFF: False,
|
||||||
|
REPEAT_MODE_ALL: True,
|
||||||
|
REPEAT_MODE_ONE: "ONE",
|
||||||
|
}
|
||||||
|
|
||||||
|
SONOS_TO_REPEAT = {meaning: mode for mode, meaning in REPEAT_TO_SONOS.items()}
|
||||||
|
|
||||||
ATTR_SONOS_GROUP = "sonos_group"
|
ATTR_SONOS_GROUP = "sonos_group"
|
||||||
|
|
||||||
UPNP_ERRORS_TO_IGNORE = ["701", "711", "712"]
|
UPNP_ERRORS_TO_IGNORE = ["701", "711", "712"]
|
||||||
@ -506,8 +515,7 @@ class SonosEntity(MediaPlayerEntity):
|
|||||||
self._player = player
|
self._player = player
|
||||||
self._player_volume = None
|
self._player_volume = None
|
||||||
self._player_muted = None
|
self._player_muted = None
|
||||||
self._shuffle = None
|
self._play_mode = None
|
||||||
self._repeat = None
|
|
||||||
self._coordinator = None
|
self._coordinator = None
|
||||||
self._sonos_group = [self]
|
self._sonos_group = [self]
|
||||||
self._status = None
|
self._status = None
|
||||||
@ -679,8 +687,7 @@ class SonosEntity(MediaPlayerEntity):
|
|||||||
def _attach_player(self):
|
def _attach_player(self):
|
||||||
"""Get basic information and add event subscriptions."""
|
"""Get basic information and add event subscriptions."""
|
||||||
try:
|
try:
|
||||||
self._shuffle = self.soco.shuffle
|
self._play_mode = self.soco.play_mode
|
||||||
self._repeat = self.soco.repeat
|
|
||||||
self.update_volume()
|
self.update_volume()
|
||||||
self._set_favorites()
|
self._set_favorites()
|
||||||
|
|
||||||
@ -725,8 +732,7 @@ class SonosEntity(MediaPlayerEntity):
|
|||||||
if new_status == "TRANSITIONING":
|
if new_status == "TRANSITIONING":
|
||||||
return
|
return
|
||||||
|
|
||||||
self._shuffle = self.soco.shuffle
|
self._play_mode = event.current_play_mode if event else self.soco.play_mode
|
||||||
self._repeat = self.soco.repeat
|
|
||||||
self._uri = None
|
self._uri = None
|
||||||
self._media_duration = None
|
self._media_duration = None
|
||||||
self._media_image_url = None
|
self._media_image_url = None
|
||||||
@ -960,19 +966,14 @@ class SonosEntity(MediaPlayerEntity):
|
|||||||
@soco_coordinator
|
@soco_coordinator
|
||||||
def shuffle(self):
|
def shuffle(self):
|
||||||
"""Shuffling state."""
|
"""Shuffling state."""
|
||||||
return self._shuffle
|
return PLAY_MODES[self._play_mode][0]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@soco_coordinator
|
@soco_coordinator
|
||||||
def repeat(self):
|
def repeat(self):
|
||||||
"""Return current repeat mode."""
|
"""Return current repeat mode."""
|
||||||
if self._repeat is True:
|
sonos_repeat = PLAY_MODES[self._play_mode][1]
|
||||||
return REPEAT_MODE_ALL
|
return SONOS_TO_REPEAT[sonos_repeat]
|
||||||
|
|
||||||
if self._repeat == "ONE":
|
|
||||||
return REPEAT_MODE_ONE
|
|
||||||
|
|
||||||
return REPEAT_MODE_OFF
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@soco_coordinator
|
@soco_coordinator
|
||||||
@ -1073,18 +1074,17 @@ class SonosEntity(MediaPlayerEntity):
|
|||||||
@soco_coordinator
|
@soco_coordinator
|
||||||
def set_shuffle(self, shuffle):
|
def set_shuffle(self, shuffle):
|
||||||
"""Enable/Disable shuffle mode."""
|
"""Enable/Disable shuffle mode."""
|
||||||
self.soco.shuffle = shuffle
|
sonos_shuffle = shuffle
|
||||||
|
sonos_repeat = PLAY_MODES[self._play_mode][1]
|
||||||
|
self.soco.play_mode = PLAY_MODE_BY_MEANING[(sonos_shuffle, sonos_repeat)]
|
||||||
|
|
||||||
@soco_error(UPNP_ERRORS_TO_IGNORE)
|
@soco_error(UPNP_ERRORS_TO_IGNORE)
|
||||||
@soco_coordinator
|
@soco_coordinator
|
||||||
def set_repeat(self, repeat):
|
def set_repeat(self, repeat):
|
||||||
"""Set repeat mode."""
|
"""Set repeat mode."""
|
||||||
repeat_map = {
|
sonos_shuffle = PLAY_MODES[self._play_mode][0]
|
||||||
REPEAT_MODE_OFF: False,
|
sonos_repeat = REPEAT_TO_SONOS[repeat]
|
||||||
REPEAT_MODE_ALL: True,
|
self.soco.play_mode = PLAY_MODE_BY_MEANING[(sonos_shuffle, sonos_repeat)]
|
||||||
REPEAT_MODE_ONE: "ONE",
|
|
||||||
}
|
|
||||||
self.soco.repeat = repeat_map[repeat]
|
|
||||||
|
|
||||||
@soco_error()
|
@soco_error()
|
||||||
def mute_volume(self, mute):
|
def mute_volume(self, mute):
|
||||||
|
@ -23,6 +23,7 @@ def soco_fixture(music_library, speaker_info, dummy_soco_service):
|
|||||||
):
|
):
|
||||||
mock_soco = mock.return_value
|
mock_soco = mock.return_value
|
||||||
mock_soco.uid = "RINCON_test"
|
mock_soco.uid = "RINCON_test"
|
||||||
|
mock_soco.play_mode = "NORMAL"
|
||||||
mock_soco.music_library = music_library
|
mock_soco.music_library = music_library
|
||||||
mock_soco.get_speaker_info.return_value = speaker_info
|
mock_soco.get_speaker_info.return_value = speaker_info
|
||||||
mock_soco.avTransport = dummy_soco_service
|
mock_soco.avTransport = dummy_soco_service
|
||||||
|
Loading…
x
Reference in New Issue
Block a user