sonos set coordinator after join/unjoin (#5584)
* sonos set coordinator after join/unjoin * fix unittest
This commit is contained in:
parent
5a7a84fad1
commit
1d4e967106
2 changed files with 9 additions and 4 deletions
|
@ -71,7 +71,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
})
|
||||
|
||||
SONOS_SCHEMA = vol.Schema({
|
||||
ATTR_ENTITY_ID: cv.entity_ids,
|
||||
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
|
||||
})
|
||||
|
||||
SONOS_JOIN_SCHEMA = SONOS_SCHEMA.extend({
|
||||
|
@ -923,17 +923,22 @@ class SonosDevice(MediaPlayerDevice):
|
|||
|
||||
def join(self, master):
|
||||
"""Join the player to a group."""
|
||||
coord = [device.soco_device for device in self.hass.data[DATA_SONOS]
|
||||
coord = [device for device in self.hass.data[DATA_SONOS]
|
||||
if device.entity_id == master]
|
||||
|
||||
if coord and master != self.entity_id:
|
||||
self._player.join(coord[0])
|
||||
coord = coord[0]
|
||||
if coord.soco_device.group.coordinator != coord.soco_device:
|
||||
coord.soco_device.unjoin()
|
||||
self._player.join(coord.soco_device)
|
||||
self._coordinator = coord
|
||||
else:
|
||||
_LOGGER.error("Master not found %s", master)
|
||||
|
||||
def unjoin(self):
|
||||
"""Unjoin the player from a group."""
|
||||
self._player.unjoin()
|
||||
self._coordinator = None
|
||||
|
||||
def snapshot(self, with_group=True):
|
||||
"""Snapshot the player."""
|
||||
|
|
|
@ -251,7 +251,7 @@ class TestSonosMediaPlayer(unittest.TestCase):
|
|||
|
||||
device_master = mock.MagicMock()
|
||||
device_master.entity_id = "media_player.test"
|
||||
device_master.soco_device = device
|
||||
device_master.soco_device = mock.MagicMock()
|
||||
self.hass.data[sonos.DATA_SONOS].append(device_master)
|
||||
|
||||
join_mock.return_value = True
|
||||
|
|
Loading…
Add table
Reference in a new issue