Skip to content

Commit

Permalink
Squeezebox grouping (#70962)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajlaud authored Apr 29, 2022
1 parent 37384f7 commit c7d3446
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions homeassistant/components/squeezebox/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ class SqueezeBoxEntity(MediaPlayerEntity):
| MediaPlayerEntityFeature.SHUFFLE_SET
| MediaPlayerEntityFeature.CLEAR_PLAYLIST
| MediaPlayerEntityFeature.STOP
| MediaPlayerEntityFeature.GROUPING
)

def __init__(self, player):
Expand Down Expand Up @@ -393,7 +394,7 @@ def shuffle(self):
return self._player.shuffle == "song"

@property
def sync_group(self):
def group_members(self):
"""List players we are synced with."""
player_ids = {
p.unique_id: p.entity_id for p in self.hass.data[DOMAIN][KNOWN_PLAYERS]
Expand All @@ -404,6 +405,11 @@ def sync_group(self):
sync_group.append(player_ids[player])
return sync_group

@property
def sync_group(self):
"""List players we are synced with. Deprecated."""
return self.group_members

@property
def query_result(self):
"""Return the result from the call_query service."""
Expand Down Expand Up @@ -560,25 +566,43 @@ async def async_call_query(self, command, parameters=None):
self._query_result = await self._player.async_query(*all_params)
_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
without asking.
"""
player_ids = {
p.entity_id: p.unique_id for p in self.hass.data[DOMAIN][KNOWN_PLAYERS]
}
if other_player_id := player_ids.get(other_player):
await self._player.async_sync(other_player_id)
else:
_LOGGER.info("Could not find player_id for %s. Not syncing", other_player)

async def async_unsync(self):
for other_player in group_members:
if other_player_id := player_ids.get(other_player):
await self._player.async_sync(other_player_id)
else:
_LOGGER.info(
"Could not find player_id for %s. Not syncing", other_player
)

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."""
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):
"""Implement the websocket media browsing helper."""
_LOGGER.debug(
Expand Down

0 comments on commit c7d3446

Please sign in to comment.