Skip to content

Commit 1d4e967

Browse files
authored
sonos set coordinator after join/unjoin (home-assistant#5584)
* sonos set coordinator after join/unjoin * fix unittest
1 parent 5a7a84f commit 1d4e967

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

homeassistant/components/media_player/sonos.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
})
7272

7373
SONOS_SCHEMA = vol.Schema({
74-
ATTR_ENTITY_ID: cv.entity_ids,
74+
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
7575
})
7676

7777
SONOS_JOIN_SCHEMA = SONOS_SCHEMA.extend({
@@ -923,17 +923,22 @@ def play_media(self, media_type, media_id, **kwargs):
923923

924924
def join(self, master):
925925
"""Join the player to a group."""
926-
coord = [device.soco_device for device in self.hass.data[DATA_SONOS]
926+
coord = [device for device in self.hass.data[DATA_SONOS]
927927
if device.entity_id == master]
928928

929929
if coord and master != self.entity_id:
930-
self._player.join(coord[0])
930+
coord = coord[0]
931+
if coord.soco_device.group.coordinator != coord.soco_device:
932+
coord.soco_device.unjoin()
933+
self._player.join(coord.soco_device)
934+
self._coordinator = coord
931935
else:
932936
_LOGGER.error("Master not found %s", master)
933937

934938
def unjoin(self):
935939
"""Unjoin the player from a group."""
936940
self._player.unjoin()
941+
self._coordinator = None
937942

938943
def snapshot(self, with_group=True):
939944
"""Snapshot the player."""

tests/components/media_player/test_sonos.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def test_sonos_group_players(self, join_mock, *args):
251251

252252
device_master = mock.MagicMock()
253253
device_master.entity_id = "media_player.test"
254-
device_master.soco_device = device
254+
device_master.soco_device = mock.MagicMock()
255255
self.hass.data[sonos.DATA_SONOS].append(device_master)
256256

257257
join_mock.return_value = True

0 commit comments

Comments
 (0)