Skip to content

Commit

Permalink
Add Sonos support for media_player.repeat_set service (#41735)
Browse files Browse the repository at this point in the history
* Add Sonos support for media_player.repeat_set service

* Update homeassistant/components/sonos/media_player.py

* Remove else for pylint

Co-authored-by: cgtobi <cgtobi@users.noreply.github.com>
  • Loading branch information
amelchio and cgtobi committed Oct 12, 2020
1 parent d006558 commit b5308bd
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions homeassistant/components/sonos/media_player.py
Expand Up @@ -33,13 +33,17 @@
MEDIA_TYPE_MUSIC,
MEDIA_TYPE_PLAYLIST,
MEDIA_TYPE_TRACK,
REPEAT_MODE_ALL,
REPEAT_MODE_OFF,
REPEAT_MODE_ONE,
SUPPORT_BROWSE_MEDIA,
SUPPORT_CLEAR_PLAYLIST,
SUPPORT_NEXT_TRACK,
SUPPORT_PAUSE,
SUPPORT_PLAY,
SUPPORT_PLAY_MEDIA,
SUPPORT_PREVIOUS_TRACK,
SUPPORT_REPEAT_SET,
SUPPORT_SEEK,
SUPPORT_SELECT_SOURCE,
SUPPORT_SHUFFLE_SET,
Expand Down Expand Up @@ -86,6 +90,7 @@
| SUPPORT_PLAY
| SUPPORT_PLAY_MEDIA
| SUPPORT_PREVIOUS_TRACK
| SUPPORT_REPEAT_SET
| SUPPORT_SEEK
| SUPPORT_SELECT_SOURCE
| SUPPORT_SHUFFLE_SET
Expand Down Expand Up @@ -502,6 +507,7 @@ def __init__(self, player):
self._player_volume = None
self._player_muted = None
self._shuffle = None
self._repeat = None
self._coordinator = None
self._sonos_group = [self]
self._status = None
Expand Down Expand Up @@ -674,6 +680,7 @@ def _attach_player(self):
"""Get basic information and add event subscriptions."""
try:
self._shuffle = self.soco.shuffle
self._repeat = self.soco.repeat
self.update_volume()
self._set_favorites()

Expand Down Expand Up @@ -719,6 +726,7 @@ def update_media(self, event=None):
return

self._shuffle = self.soco.shuffle
self._repeat = self.soco.repeat
self._uri = None
self._media_duration = None
self._media_image_url = None
Expand Down Expand Up @@ -954,6 +962,18 @@ def shuffle(self):
"""Shuffling state."""
return self._shuffle

@property
@soco_coordinator
def repeat(self):
"""Return current repeat mode."""
if self._repeat is True:
return REPEAT_MODE_ALL

if self._repeat == "ONE":
return REPEAT_MODE_ONE

return REPEAT_MODE_OFF

@property
@soco_coordinator
def media_content_id(self):
Expand Down Expand Up @@ -1055,6 +1075,17 @@ def set_shuffle(self, shuffle):
"""Enable/Disable shuffle mode."""
self.soco.shuffle = shuffle

@soco_error(UPNP_ERRORS_TO_IGNORE)
@soco_coordinator
def set_repeat(self, repeat):
"""Set repeat mode."""
repeat_map = {
REPEAT_MODE_OFF: False,
REPEAT_MODE_ALL: True,
REPEAT_MODE_ONE: "ONE",
}
self.soco.repeat = repeat_map[repeat]

@soco_error()
def mute_volume(self, mute):
"""Mute (true) or unmute (false) media player."""
Expand Down

0 comments on commit b5308bd

Please sign in to comment.