Skip to content

Commit

Permalink
fix for group player power
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Sep 18, 2020
1 parent 5a29490 commit fb6cded
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion music_assistant/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""All constants for Music Assistant."""

__version__ = "0.0.32"
__version__ = "0.0.33"
REQUIRED_PYTHON_VER = "3.7"

CONF_USERNAME = "username"
Expand Down
43 changes: 28 additions & 15 deletions music_assistant/player_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,32 +316,40 @@ async def async_cmd_stop(self, player_id: str) -> None:
:param player_id: player_id of the player to handle the command.
"""
# TODO: redirect playback related commands to parent player?
return await self.get_player_provider(player_id).async_cmd_stop(player_id)
player = self.get_player(player_id)
queue_player_id = player.active_queue
return await self.get_player_provider(queue_player_id).async_cmd_stop(
queue_player_id
)

async def async_cmd_play(self, player_id: str) -> None:
"""
Send PLAY command to given player.
:param player_id: player_id of the player to handle the command.
"""
# power on at play request
await self.async_cmd_power_on(player_id)
player = self.get_player(player_id)
queue_player_id = player.active_queue
# unpause if paused else resume queue
if player.state == PlayerState.Paused:
return await self.get_player_provider(player_id).async_cmd_play(player_id)
return await self._player_queues[player_id].async_resume()
# TODO: redirect playback related commands to parent player?
return await self.get_player_provider(queue_player_id).async_cmd_play(
queue_player_id
)
# power on at play request
await self.async_cmd_power_on(player_id)
return await self._player_queues[queue_player_id].async_resume()

async def async_cmd_pause(self, player_id: str):
"""
Send PAUSE command to given player.
:param player_id: player_id of the player to handle the command.
"""
return await self.get_player_provider(player_id).async_cmd_pause(player_id)
# TODO: redirect playback related commands to parent player?
player = self.get_player(player_id)
queue_player_id = player.active_queue
return await self.get_player_provider(queue_player_id).async_cmd_pause(
queue_player_id
)

async def async_cmd_play_pause(self, player_id: str):
"""
Expand All @@ -360,15 +368,19 @@ async def async_cmd_next(self, player_id: str):
:param player_id: player_id of the player to handle the command.
"""
return await self.get_player_queue(player_id).async_next()
player = self.get_player(player_id)
queue_player_id = player.active_queue
return await self.get_player_queue(queue_player_id).async_next()

async def async_cmd_previous(self, player_id: str):
"""
Send PREVIOUS TRACK command to given player.
:param player_id: player_id of the player to handle the command.
"""
return await self.get_player_queue(player_id).async_previous()
player = self.get_player(player_id)
queue_player_id = player.active_queue
return await self.get_player_queue(queue_player_id).async_previous()

async def async_cmd_power_on(self, player_id: str) -> None:
"""
Expand Down Expand Up @@ -405,19 +417,20 @@ async def async_cmd_power_off(self, player_id: str) -> None:
if player.is_group_player:
# player is group, turn off all childs
for child_player_id in player.group_childs:
if self._players.get(child_player_id):
child_player = self.get_player(child_player_id)
if child_player and child_player.powered:
await self.async_cmd_power_off(child_player_id)
else:
# if this was the last powered player in the group, turn off group
for parent_player_id in player.group_parents:
parent_player = self._players.get(parent_player_id)
if not parent_player:
parent_player = self.get_player(parent_player_id)
if not parent_player or not parent_player.powered:
continue
has_powered_players = False
for child_player_id in parent_player.group_childs:
if child_player_id == player_id:
continue
child_player = self._players.get(child_player_id)
child_player = self.get_player(child_player_id)
if child_player and child_player.powered:
has_powered_players = True
break
Expand Down

0 comments on commit fb6cded

Please sign in to comment.