Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions custom_components/mass_queue/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from homeassistant.helpers import entity_registry as er

from .const import (
ATTR_COMMAND,
ATTR_DATA,
ATTR_LIMIT,
ATTR_LIMIT_AFTER,
ATTR_LIMIT_BEFORE,
Expand All @@ -36,6 +38,7 @@
SERVICE_MOVE_QUEUE_ITEM_UP,
SERVICE_PLAY_QUEUE_ITEM,
SERVICE_REMOVE_QUEUE_ITEM,
SERVICE_SEND_COMMAND,
)
from .controller import MassQueueController
from .schemas import (
Expand All @@ -46,6 +49,7 @@
QUEUE_ITEM_SCHEMA,
QUEUE_ITEMS_SERVICE_SCHEMA,
REMOVE_QUEUE_ITEM_SERVICE_SCHEMA,
SEND_COMMAND_SERVICE_SCHEMA,
)

if TYPE_CHECKING:
Expand Down Expand Up @@ -115,6 +119,13 @@ def register_actions(self) -> None:
schema=MOVE_QUEUE_ITEM_NEXT_SERVICE_SCHEMA,
supports_response=SupportsResponse.NONE,
)
self._hass.services.async_register(
DOMAIN,
SERVICE_SEND_COMMAND,
self.send_command,
schema=SEND_COMMAND_SERVICE_SCHEMA,
supports_response=SupportsResponse.OPTIONAL,
)

def get_queue_id(self, entity_id: str):
"""Get the queue ID for a player."""
Expand Down Expand Up @@ -160,6 +171,13 @@ def _format_queue_item(self, queue_item: dict) -> dict:
)
return response

async def send_command(self, call: ServiceCall) -> ServiceResponse:
"""Sends command to Music Assistant and returns response."""
command = call.data[ATTR_COMMAND]
data = call.data.get(ATTR_DATA)
response = await self._controller.send_command(command, data)
return {"response": response}

async def get_queue_items(self, call: ServiceCall) -> ServiceResponse:
"""Get all items in queue."""
entity_id = call.data[ATTR_PLAYER_ENTITY]
Expand Down
10 changes: 6 additions & 4 deletions custom_components/mass_queue/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@
SERVICE_MOVE_QUEUE_ITEM_UP = "move_queue_item_up"
SERVICE_MOVE_QUEUE_ITEM_DOWN = "move_queue_item_down"
SERVICE_MOVE_QUEUE_ITEM_NEXT = "move_queue_item_next"
SERVICE_SEND_COMMAND = "send_command"

ATTR_CONFIG_ENTRY_ID = "config_entry_id"

ATTR_PLAYER_ENTITY = "entity"
ATTR_OFFSET = "offset"
ATTR_LIMIT = "limit"
ATTR_LIMIT_BEFORE = "limit_before"
ATTR_LIMIT_AFTER = "limit_after"
ATTR_LIMIT_BEFORE = "limit_before"
ATTR_QUEUE_ITEM_ID = "queue_item_id"
ATTR_MEDIA_TITLE = "media_title"
ATTR_MEDIA_ALBUM_NAME = "media_album_name"
ATTR_MEDIA_ARTIST = "media_artist"
ATTR_MEDIA_CONTENT_ID = "media_content_id"
ATTR_MEDIA_IMAGE = "media_image"
ATTR_OFFSET = "offset"
ATTR_PLAYER_ENTITY = "entity"
ATTR_QUEUE_ITEMS = "queue_items"
ATTR_COMMAND = "command"
ATTR_DATA = "data"
LOGGER = logging.getLogger(__package__)

DEFAULT_QUEUE_ITEMS_LIMIT = 500
Expand Down
5 changes: 5 additions & 0 deletions custom_components/mass_queue/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ def update_player_queue(self, player_id: str):
queue_id = get_queue_id_from_player_data(player)
self.players.update(player_id, queue_id)

async def send_command(self, command: str, data: dict | None = None):
"""Sends command to Music Assistant and returns response."""
data = data if data else {}
return await self._client.send_command(command, require_schema=None, **data)

async def get_player_queue(self, player_id: str):
"""Gets queue items for single Music Assistant queue."""
player = self._client.players.get(player_id)
Expand Down
9 changes: 9 additions & 0 deletions custom_components/mass_queue/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from homeassistant.helpers import config_validation as cv

from .const import (
ATTR_COMMAND,
ATTR_DATA,
ATTR_LIMIT,
ATTR_LIMIT_AFTER,
ATTR_LIMIT_BEFORE,
Expand Down Expand Up @@ -79,3 +81,10 @@
vol.Required(ATTR_QUEUE_ITEM_ID): str,
},
)

SEND_COMMAND_SERVICE_SCHEMA = vol.Schema(
{
vol.Required(ATTR_COMMAND): str,
vol.Optional(ATTR_DATA, default={}): dict,
},
)
9 changes: 9 additions & 0 deletions custom_components/mass_queue/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,12 @@ play_queue_item:
entity:
domain: media_player
integration: music_assistant
send_command:
fields:
command:
required: true
selector:
text:
data:
required: false
default: {}
Loading