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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ The WebSocket commands below can be used by custom cards/integrations along with
| `type` | str | Yes | Must be `mass_queue/download_and_encode_image` |
| `url` | str | Yes | URL of media to download. |

`mass_queue/get_user_info`: Returns a single image for a media item as a Base64 encoded string. Useful when avoiding mixed-content or when accessing local media outside of your network

| Parameter | Type | Required | Description |
|-------------------|------|----------|---------|-----------------------------|
| `type` | str | Yes | Must be `mass_queue/get_user_info` |
| `entity_id` | str | Yes | URL of media to download. |
| `username` | str | Yes | Username of user to return info for. |

## Installation

1. Download and install the integration by using the button above.
Expand Down
2 changes: 2 additions & 0 deletions custom_components/mass_queue/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
api_download_and_encode_image,
api_download_images,
api_get_entity_info,
api_get_user_info,
)

if TYPE_CHECKING:
Expand Down Expand Up @@ -146,6 +147,7 @@ async def on_hass_stop(event: Event) -> None: # noqa: ARG001
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)
websocket_api.async_register_command(hass, api_get_user_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
9 changes: 9 additions & 0 deletions custom_components/mass_queue/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,15 @@ async def download_and_encode_image(url: str, hass: HomeAssistant):
return f"data:image;base64,{base64.b64encode(read).decode('utf-8')}"


async def get_user_info(hass: HomeAssistant, entity_id: str, username: str):
"""Returns the user information for the given username."""
client = get_mass_client(hass, entity_id)
users = await client.auth.list_users()
LOGGER.debug(f"Client: {client}")
LOGGER.debug(f"Users: {users}")
return [user.to_dict() for user in users if user.username == username][0]


def get_entity_info(hass: HomeAssistant, entity_id: str):
"""Gets the server and client info for a given player."""
client = get_mass_client(hass, entity_id)
Expand Down
23 changes: 23 additions & 0 deletions custom_components/mass_queue/websocket_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
download_and_encode_image,
download_single_image_from_image_data,
get_entity_info,
get_user_info,
)


Expand Down Expand Up @@ -101,3 +102,25 @@ async def get_playlist_items(
msg: dict,
) -> None:
"""Retrieves all playlist items."""


@websocket_api.websocket_command(
{
vol.Required("type"): "mass_queue/get_user_info",
vol.Required("entity_id"): str,
vol.Required("username"): str,
},
)
@websocket_api.async_response
async def api_get_user_info(
hass: HomeAssistant,
connection: websocket_api.ActiveConnection,
msg: dict,
) -> None:
"""Returns the information for a given user."""
entity_id = msg["entity_id"]
username = msg["username"]
LOGGER.debug(f"Received message {msg}")
result = await get_user_info(hass, entity_id, username)
LOGGER.debug(f"Sending result {result}")
connection.send_result(msg["id"], result)
4 changes: 4 additions & 0 deletions docs/response_schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ synced_to: str| None # Player(s) which are currently synced/grouped/joine
type: str
```

### GetUser
*See [music_assistant_models.auth.User](https://github.com/music-assistant/models/blob/0f2ad708ab26d2cc2ae008872afc00cd4a795380/music_assistant_models/auth.py#L29)*


### DownloadAndEncodeImageResponseSchema

```yaml
Expand Down
Loading