Squeezebox grouping (#70962)

This commit is contained in:
Raj Laud 2022-04-29 00:39:58 -04:00 committed by GitHub
parent 37384f7eb3
commit c7d344692f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -238,6 +238,7 @@ class SqueezeBoxEntity(MediaPlayerEntity):
| MediaPlayerEntityFeature.SHUFFLE_SET | MediaPlayerEntityFeature.SHUFFLE_SET
| MediaPlayerEntityFeature.CLEAR_PLAYLIST | MediaPlayerEntityFeature.CLEAR_PLAYLIST
| MediaPlayerEntityFeature.STOP | MediaPlayerEntityFeature.STOP
| MediaPlayerEntityFeature.GROUPING
) )
def __init__(self, player): def __init__(self, player):
@ -393,7 +394,7 @@ class SqueezeBoxEntity(MediaPlayerEntity):
return self._player.shuffle == "song" return self._player.shuffle == "song"
@property @property
def sync_group(self): def group_members(self):
"""List players we are synced with.""" """List players we are synced with."""
player_ids = { player_ids = {
p.unique_id: p.entity_id for p in self.hass.data[DOMAIN][KNOWN_PLAYERS] p.unique_id: p.entity_id for p in self.hass.data[DOMAIN][KNOWN_PLAYERS]
@ -404,6 +405,11 @@ class SqueezeBoxEntity(MediaPlayerEntity):
sync_group.append(player_ids[player]) sync_group.append(player_ids[player])
return sync_group return sync_group
@property
def sync_group(self):
"""List players we are synced with. Deprecated."""
return self.group_members
@property @property
def query_result(self): def query_result(self):
"""Return the result from the call_query service.""" """Return the result from the call_query service."""
@ -560,9 +566,9 @@ class SqueezeBoxEntity(MediaPlayerEntity):
self._query_result = await self._player.async_query(*all_params) self._query_result = await self._player.async_query(*all_params)
_LOGGER.debug("call_query got result %s", self._query_result) _LOGGER.debug("call_query got result %s", self._query_result)
async def async_sync(self, other_player): async def async_join_players(self, group_members):
""" """
Add another Squeezebox player to this player's sync group. Add other Squeezebox players to this player's sync group.
If the other player is a member of a sync group, it will leave the current sync group If the other player is a member of a sync group, it will leave the current sync group
without asking. without asking.
@ -570,15 +576,33 @@ class SqueezeBoxEntity(MediaPlayerEntity):
player_ids = { player_ids = {
p.entity_id: p.unique_id for p in self.hass.data[DOMAIN][KNOWN_PLAYERS] p.entity_id: p.unique_id for p in self.hass.data[DOMAIN][KNOWN_PLAYERS]
} }
for other_player in group_members:
if other_player_id := player_ids.get(other_player): if other_player_id := player_ids.get(other_player):
await self._player.async_sync(other_player_id) await self._player.async_sync(other_player_id)
else: else:
_LOGGER.info("Could not find player_id for %s. Not syncing", other_player) _LOGGER.info(
"Could not find player_id for %s. Not syncing", other_player
)
async def async_unsync(self): async def async_sync(self, other_player):
"""Sync this Squeezebox player to another. Deprecated."""
_LOGGER.warning(
"Service squeezebox.sync is deprecated; use media_player.join_players instead"
)
await self.async_join_players([other_player])
async def async_unjoin_player(self):
"""Unsync this Squeezebox player.""" """Unsync this Squeezebox player."""
await self._player.async_unsync() await self._player.async_unsync()
async def async_unsync(self):
"""Unsync this Squeezebox player. Deprecated."""
_LOGGER.warning(
"Service squeezebox.unsync is deprecated; use media_player.unjoin_player instead"
)
await self.async_unjoin_player()
async def async_browse_media(self, media_content_type=None, media_content_id=None): async def async_browse_media(self, media_content_type=None, media_content_id=None):
"""Implement the websocket media browsing helper.""" """Implement the websocket media browsing helper."""
_LOGGER.debug( _LOGGER.debug(