From 7aaedbdc42804eb4b87d0dce687b2f65635d4e0b Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Thu, 21 Aug 2025 09:02:40 -0400 Subject: [PATCH 1/3] Reorder Attributes --- custom_components/mass_queue/const.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/custom_components/mass_queue/const.py b/custom_components/mass_queue/const.py index 619a8b9..2696aa3 100644 --- a/custom_components/mass_queue/const.py +++ b/custom_components/mass_queue/const.py @@ -12,18 +12,17 @@ SERVICE_MOVE_QUEUE_ITEM_NEXT = "move_queue_item_next" 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" LOGGER = logging.getLogger(__package__) From a60773a2820e5ffae0b8e6048a067dfd1b8f8211 Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Thu, 21 Aug 2025 09:30:33 -0400 Subject: [PATCH 2/3] Add `send_command` --- custom_components/mass_queue/actions.py | 18 ++++++++++++++++++ custom_components/mass_queue/const.py | 3 +++ custom_components/mass_queue/controller.py | 5 +++++ custom_components/mass_queue/schemas.py | 9 +++++++++ custom_components/mass_queue/services.yaml | 9 +++++++++ 5 files changed, 44 insertions(+) diff --git a/custom_components/mass_queue/actions.py b/custom_components/mass_queue/actions.py index 8469164..6e07382 100644 --- a/custom_components/mass_queue/actions.py +++ b/custom_components/mass_queue/actions.py @@ -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, @@ -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 ( @@ -46,6 +49,7 @@ QUEUE_ITEM_SCHEMA, QUEUE_ITEMS_SERVICE_SCHEMA, REMOVE_QUEUE_ITEM_SERVICE_SCHEMA, + SEND_COMMAND_SERVICE_SCHEMA, ) if TYPE_CHECKING: @@ -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.""" @@ -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] diff --git a/custom_components/mass_queue/const.py b/custom_components/mass_queue/const.py index 2696aa3..159b601 100644 --- a/custom_components/mass_queue/const.py +++ b/custom_components/mass_queue/const.py @@ -10,6 +10,7 @@ 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_LIMIT = "limit" @@ -24,6 +25,8 @@ 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 diff --git a/custom_components/mass_queue/controller.py b/custom_components/mass_queue/controller.py index 07a2c4b..bbd7e3a 100644 --- a/custom_components/mass_queue/controller.py +++ b/custom_components/mass_queue/controller.py @@ -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) diff --git a/custom_components/mass_queue/schemas.py b/custom_components/mass_queue/schemas.py index 1fa5f9b..3d1d109 100644 --- a/custom_components/mass_queue/schemas.py +++ b/custom_components/mass_queue/schemas.py @@ -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, @@ -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, + }, +) diff --git a/custom_components/mass_queue/services.yaml b/custom_components/mass_queue/services.yaml index 0812d4b..d439d38 100644 --- a/custom_components/mass_queue/services.yaml +++ b/custom_components/mass_queue/services.yaml @@ -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: {} From 7f2a8a8452c713c3ee4d8de4a5d9bd6910b8585f Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Thu, 21 Aug 2025 09:34:13 -0400 Subject: [PATCH 3/3] Linting --- custom_components/mass_queue/actions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/mass_queue/actions.py b/custom_components/mass_queue/actions.py index 6e07382..ab1d536 100644 --- a/custom_components/mass_queue/actions.py +++ b/custom_components/mass_queue/actions.py @@ -176,7 +176,7 @@ async def send_command(self, call: ServiceCall) -> ServiceResponse: command = call.data[ATTR_COMMAND] data = call.data.get(ATTR_DATA) response = await self._controller.send_command(command, data) - return {'response': response} + return {"response": response} async def get_queue_items(self, call: ServiceCall) -> ServiceResponse: """Get all items in queue."""