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
9 changes: 7 additions & 2 deletions custom_components/mass_queue/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@
)
from .const import DOMAIN, LOGGER
from .services import register_actions
from .utils import api_download_and_encode_image, download_images
from .websocket_commands import (
api_download_and_encode_image,
api_download_images,
api_get_entity_info,
)

if TYPE_CHECKING:
from homeassistant.core import HomeAssistant
Expand Down Expand Up @@ -121,8 +125,9 @@ async def on_hass_stop(event: Event) -> None: # noqa: ARG001
actions = await setup_controller_and_actions(hass, mass, entry)
register_actions(hass)
entry.runtime_data = MusicAssistantQueueEntryData(mass, actions, listen_task)
websocket_api.async_register_command(hass, download_images)
websocket_api.async_register_command(hass, api_download_images)
websocket_api.async_register_command(hass, api_download_and_encode_image)
websocket_api.async_register_command(hass, api_get_entity_info)

# If the listen task is already failed, we need to raise ConfigEntryNotReady
if listen_task.done() and (listen_error := listen_task.exception()) is not None:
Expand Down
22 changes: 12 additions & 10 deletions custom_components/mass_queue/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,38 @@

DOMAIN = "mass_queue"
DEFAULT_NAME = "Music Assistant Queue Items"
SERVICE_CLEAR_QUEUE_FROM_HERE = "clear_queue_from_here"
SERVICE_GET_GROUP_VOLUME = "get_group_volume"
SERVICE_GET_QUEUE_ITEMS = "get_queue_items"
SERVICE_GET_RECOMMENDATIONS = "get_recommendations"
SERVICE_PLAY_QUEUE_ITEM = "play_queue_item"
SERVICE_REMOVE_QUEUE_ITEM = "remove_queue_item"
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_MOVE_QUEUE_ITEM_UP = "move_queue_item_up"
SERVICE_REMOVE_QUEUE_ITEM = "remove_queue_item"
SERVICE_SEND_COMMAND = "send_command"
SERVICE_SET_GROUP_VOLUME = "set_group_volume"
SERVICE_UNFAVORITE_CURRENT_ITEM = "unfavorite_current_item"
ATTR_QUEUE_ID = "active_queue"

ATTR_COMMAND = "command"
ATTR_CONFIG_ENTRY_ID = "config_entry_id"
ATTR_LOCAL_IMAGE_ENCODED = "local_image_encoded"
ATTR_DATA = "data"
ATTR_FAVORITE = "favorite"
ATTR_LIMIT = "limit"
ATTR_LIMIT_AFTER = "limit_after"
ATTR_LIMIT_BEFORE = "limit_before"
ATTR_QUEUE_ITEM_ID = "queue_item_id"
ATTR_MEDIA_TITLE = "media_title"
ATTR_LOCAL_IMAGE_ENCODED = "local_image_encoded"
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_MEDIA_TITLE = "media_title"
ATTR_OFFSET = "offset"
ATTR_PLAYER_ENTITY = "entity"
ATTR_QUEUE_ITEMS = "queue_items"
ATTR_COMMAND = "command"
ATTR_DATA = "data"
ATTR_FAVORITE = "favorite"
ATTR_PROVIDERS = "providers"
ATTR_QUEUE_ID = "active_queue"
ATTR_QUEUE_ITEM_ID = "queue_item_id"
ATTR_QUEUE_ITEMS = "queue_items"
ATTR_VOLUME_LEVEL = "volume_level"

CONF_DOWNLOAD_LOCAL = "download_local"
Expand Down
3 changes: 2 additions & 1 deletion custom_components/mass_queue/icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"unfavorite_current_item": { "service": "mdi:heart-remove" },
"get_recommendations": { "service": "mdi:creation"},
"get_group_volume": { "service": "mdi:speaker-multiple"},
"set_group_volume": { "service": "mdi:speaker-multiple"}
"set_group_volume": { "service": "mdi:speaker-multiple"},
"clear_queue_from_here": { "service": "mdi:playlist-remove"}
}
}
6 changes: 6 additions & 0 deletions custom_components/mass_queue/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
ATTR_VOLUME_LEVEL,
)

CLEAR_QUEUE_FROM_HERE_SERVICE_SCHEMA = vol.Schema(
{
vol.Required(ATTR_PLAYER_ENTITY): str,
},
)

GET_GROUP_VOLUME_SERVICE_SCHEMA = vol.Schema(
{
vol.Required(ATTR_PLAYER_ENTITY): str,
Expand Down
41 changes: 41 additions & 0 deletions custom_components/mass_queue/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
from .const import (
ATTR_CONFIG_ENTRY_ID,
ATTR_PLAYER_ENTITY,
ATTR_QUEUE_ITEM_ID,
DOMAIN,
LOGGER,
SERVICE_CLEAR_QUEUE_FROM_HERE,
SERVICE_GET_GROUP_VOLUME,
SERVICE_GET_QUEUE_ITEMS,
SERVICE_GET_RECOMMENDATIONS,
Expand All @@ -25,6 +28,7 @@
SERVICE_UNFAVORITE_CURRENT_ITEM,
)
from .schemas import (
CLEAR_QUEUE_FROM_HERE_SERVICE_SCHEMA,
GET_GROUP_VOLUME_SERVICE_SCHEMA,
GET_RECOMMENDATIONS_SERVICE_SCHEMA,
MOVE_QUEUE_ITEM_DOWN_SERVICE_SCHEMA,
Expand Down Expand Up @@ -120,6 +124,13 @@ def register_actions(hass) -> None:
schema=SET_GROUP_VOLUME_SERVICE_SCHEMA,
supports_response=SupportsResponse.NONE,
)
hass.services.async_register(
DOMAIN,
SERVICE_CLEAR_QUEUE_FROM_HERE,
clear_queue_from_here,
schema=CLEAR_QUEUE_FROM_HERE_SERVICE_SCHEMA,
supports_response=SupportsResponse.NONE,
)


async def get_queue_items(call: ServiceCall):
Expand Down Expand Up @@ -211,3 +222,33 @@ async def set_group_volume(call: ServiceCall):
hass = call.hass
actions = get_entity_actions_controller(hass, entity_id)
await actions.set_group_volume(call)


def filter_queue_after(queue, current_idx):
"""Returns all items after the current active track."""
if current_idx == len(queue):
return []
return queue[current_idx + 1 :]


async def clear_queue_from_here(call: ServiceCall):
"""Service wrapper to clear queue from point."""
entity_id = call.data[ATTR_PLAYER_ENTITY]
hass = call.hass
actions = get_entity_actions_controller(hass, entity_id)
current_idx = await actions.get_queue_index(entity_id)
LOGGER.debug(f"Current Index: {current_idx}")
queue_id = actions.get_queue_id(entity_id)
LOGGER.debug(f"Queue ID: {queue_id}")
queue = actions._controller.queues.get(queue_id)
LOGGER.debug(f"Queue length: {len(queue)}")
client = actions._client
if len(queue) == current_idx:
return
items = queue[current_idx + 1 :]
LOGGER.debug(f"Filtered length: {len(items)}")
LOGGER.debug(f"First item to remove {items[0]}")
LOGGER.debug(f"Last item to remove {items[-1]}")
for item in items:
queue_item_id = item[ATTR_QUEUE_ITEM_ID]
await client.player_queues.queue_command_delete(queue_id, queue_item_id)
11 changes: 11 additions & 0 deletions custom_components/mass_queue/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,14 @@ set_group_volume:
step: 1
unit_of_measurement: "%"
mode: slider

clear_queue_from_here:
fields:
entity:
name: Entity
description: Music Assistant Media Player Entity
required: true
selector:
entity:
domain: media_player
integration: music_assistant
10 changes: 10 additions & 0 deletions custom_components/mass_queue/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,16 @@
"description": "Volume level to set the player to."
}
}
},
"clear_queue_from_here": {
"name": "Clear Queue From Here",
"description": "Clears all items before/after the current track in a queue.",
"fields": {
"entity": {
"name": "Entity",
"description": "Music Assistant Media Player Entity."
}
}
}
}
}
57 changes: 57 additions & 0 deletions custom_components/mass_queue/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
"reconfigure_successful": "[%key:common::config_flow::abort::reconfigure_successful%]"
}
},
"options": {
"step": {
"init": {
"data": {
"download_local": "Attempt fallback support for local media images. May cause performance issues. Only enable if you cannot see media images for your players."
}
}
}
},
"issues": {
"invalid_server_version": {
"title": "The Music Assistant server is not the correct version",
Expand Down Expand Up @@ -161,6 +170,54 @@
"description": "Music Assistant Media Player Entity."
}
}
},
"get_recommendations": {
"name": "Get Recommendations",
"description": "Get recommendations from your music providers.",
"fields": {
"entity": {
"name": "Entity",
"description": "Music Assistant Media Player Entity."
},
"providers": {
"name": "Providers",
"description": "Limit recommendations to the specified providers."
}
}
},
"get_group_volume": {
"name": "Get Group Volume",
"description": "Returns the volume for a player group.",
"fields": {
"entity": {
"name": "Entity",
"description": "Music Assistant Media Player Entity."
}
}
},
"set_group_volume": {
"name": "Set Group Volume",
"description": "Sets the volume for a player group.",
"fields": {
"entity": {
"name": "Entity",
"description": "Music Assistant Media Player Entity."
},
"volume_level": {
"name": "Volume Level",
"description": "Volume level to set the player to."
}
}
},
"clear_queue_from_here": {
"name": "Clear Queue From Here",
"description": "Clears all items before/after the current track in a queue.",
"fields": {
"entity": {
"name": "Entity",
"description": "Music Assistant Media Player Entity."
}
}
}
}
}
Loading
Loading