mass_queue icon indicating copy to clipboard operation
mass_queue copied to clipboard

Call to get_queue_items fails

Open jasongillis opened this issue 1 year ago • 7 comments

Trying to make use of mass_card, but that's causing a huge number of errors in my Home Assistant logs. This seems to boil down to mass_queue.get_queue_items that has an issue. If I call mass_queue.get_queue_items from the HA Developer Tools Actions UI using the following YAML:

action: mass_queue.get_queue_items
data:
  entity: media_player.portable
2025-08-01 17:03:26.554 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Unexpected error for call_service at pos 1: 'NoneType' object is not subscriptable
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 524, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1012, in _async_step_call_service
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<9 lines>...
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 624, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2802, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2845, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/mass_queue/actions.py", line 100, in get_queue_items
    entity_id: [_format_queue_item(item) for item in queue_items]
                ~~~~~~~~~~~~~~~~~~^^^^^^
  File "/config/custom_components/mass_queue/actions.py", line 58, in _format_queue_item
    media_album_name = media['album']['name']
                       ~~~~~~~~~~~~~~^^^^^^^^
TypeError: 'NoneType' object is not subscriptable
2025-08-01 17:03:26.556 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140731391335360] Error handling message: Unknown error (unknown_error) Jason Gillis from 172.16.0.5 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:140.0) Gecko/20100101 Firefox/140.0)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 28, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 823, in handle_execute_script
    script_result = await script_obj.async_run(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
        msg.get("variables"), context=context
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1836, in async_run
    return await asyncio.shield(create_eager_task(run.async_run()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 460, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 526, in _async_step
    self._handle_exception(
    ~~~~~~~~~~~~~~~~~~~~~~^
        ex, continue_on_error, self._log_exceptions or log_exceptions
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 556, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 524, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1012, in _async_step_call_service
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<9 lines>...
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 624, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2802, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2845, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/mass_queue/actions.py", line 100, in get_queue_items
    entity_id: [_format_queue_item(item) for item in queue_items]
                ~~~~~~~~~~~~~~~~~~^^^^^^
  File "/config/custom_components/mass_queue/actions.py", line 58, in _format_queue_item
    media_album_name = media['album']['name']
                       ~~~~~~~~~~~~~~^^^^^^^^
TypeError: 'NoneType' object is not subscriptable

I'm not sure why this is failing because I can call music_assistant.get_queue just fine:

action: music_assistant.get_queue
data: {}
target:
  entity_id: media_player.portable

Result:

media_player.portable:
  queue_id: RINCON_949F3E0B9F4A01400
  active: true
  name: Portable
  items: 11
  shuffle_enabled: false
  repeat_mode: "off"
  current_index: 3
  elapsed_time: 417
  current_item:
    queue_item_id: d4dd1fb64cb94f3ab611a160ea77cfc4
    name: Jane's Addiction - Ted, Just Admit It...
    duration: 442
    media_item:
      media_type: track
      uri: spotify://track/2l7iDl470hxtX7FkzAA3wz
      name: Ted, Just Admit It...
      version: ""
      image: https://i.scdn.co/image/ab67616d0000b2738765ac8eae3b054a1750419d
      artists:
        - media_type: artist
          uri: spotify://artist/02NfyD6AlLA12crYzw5YcR
          name: Jane's Addiction
          version: ""
          image: null
    stream_title: null
    stream_details:
      content_type: nut
      sample_rate: 44100
      bit_depth: 16
      provider: spotify
      item_id: 2l7iDl470hxtX7FkzAA3wz
  next_item:
    queue_item_id: a582bff80d44457f91342927e1842f6b
    name: Jane's Addiction - Standing in the Shower...Thinking
    duration: 185
    media_item:
      media_type: track
      uri: spotify://track/7DzT745Oi9NI016FEkjWNa
      name: Standing in the Shower...Thinking
      version: ""
      image: null
      artists:
        - media_type: artist
          uri: spotify://artist/02NfyD6AlLA12crYzw5YcR
          name: Jane's Addiction
          version: ""
          image: null
    stream_title: null

Is there some config I might be missing or something else I can check?

I'm using 0.5.1 of mass_card and 0.1.0 of mass_queue.
HASS revision is 2025.6.3.
MASS is 2.5.5.

jasongillis avatar Aug 02 '25 00:08 jasongillis

That's interesting. It seems that your media items aren't reporting any album data.

I just released a beta version (v0.1.1-b1) - would you mind trying it out?

droans avatar Aug 04 '25 14:08 droans

Thanks for the update!

Unfortunately, the results are similar:

2025-08-04 08:02:35.644 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140730927622368] Unexpected exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 250, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<7 lines>...
    )
    ^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2802, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2845, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/mass_queue/actions.py", line 108, in get_queue_items
    entity_id: [_format_queue_item(item) for item in queue_items]
                ~~~~~~~~~~~~~~~~~~^^^^^^
  File "/config/custom_components/mass_queue/actions.py", line 60, in _format_queue_item
    media_album_name = media_album.get('name')
                       ^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get'

Not sure if it's helpful, but I stuffed a call to pprint.pformat() in actions.py and this is what the queue_item object looks like that's passed in to _format_queue_item:

2025-08-04 09:05:13.432 ERROR (MainThread) [custom_components.mass_queue] QueueItem(queue_id='RINCON_949F3E0B9F4A01400',
          queue_item_id='b723b99e5cdd4b0c917da548a2815b50',
          name="Jane's Addiction - Up the Beach",
          duration=181,
          sort_index=1,
          streamdetails=None,
          media_item=Track(item_id='7CByzrzR4LCBxVI7lM8Ggv',
                           provider='spotify',
                           name='Up the Beach',
                           version='',
                           sort_name='up the beach',
                           uri='spotify://track/7CByzrzR4LCBxVI7lM8Ggv',
                           external_ids=set(),
                           is_playable=True,
                           translation_key=None,
                           media_type=<MediaType.TRACK: 'track'>,
                           provider_mappings={ ProviderMapping(item_id='7CByzrzR4LCBxVI7lM8Ggv',
                                                               provider_domain='spotify',
                                                               provider_instance='spotify--tjUKJNCj',
                                                               available=True,
                                                               audio_format=AudioFormat(content_type=<ContentType.OGG: 'ogg'>,
                                                                                        codec_type=<ContentType.UNKNOWN: '?'>,
                                                                                        sample_rate=44100,
                                                                                        bit_depth=16,
                                                                                        channels=2,
                                                                                        output_format_str='ogg',
                                                                                        bit_rate=320),
                                                               url='https://open.spotify.com/track/7CByzrzR4LCBxVI7lM8Ggv',
                                                               details=None)},
                           metadata=MediaItemMetadata(description=None,
                                                      review=None,
                                                      explicit=False,
                                                      images=None,
                                                      genres=None,
                                                      mood=None,
                                                      style=None,
                                                      copyright=None,
                                                      lyrics=None,
                                                      label=None,
                                                      links=None,
                                                      performers=None,
                                                      preview='https://p.scdn.co/mp3-preview/daeb855fb29797ac0c484b0788dcbb2e05074d2e?cid=2eb96f9b37494be1824999d58028a305',
                                                      popularity=None,
                                                      release_date=None,
                                                      languages=None,
                                                      chapters=None,
                                                      last_refresh=None),
                           favorite=False,
                           position=None,
                           duration=181,
                           artists=[ ItemMapping(item_id='02NfyD6AlLA12crYzw5YcR',
                                                 provider='spotify',
                                                 name="Jane's Addiction",
                                                 version='',
                                                 sort_name="jane's addiction",
                                                 uri='spotify://artist/02NfyD6AlLA12crYzw5YcR',
                                                 external_ids=set(),
                                                 is_playable=True,
                                                 translation_key=None,
                                                 media_type=<MediaType.ARTIST: 'artist'>,
                                                 available=True,
                                                 image=None)],
                           album=None,
                           disc_number=1,
                           track_number=1),
          image=None,
          index=0,
          available=True)

jasongillis avatar Aug 04 '25 16:08 jasongillis

Ah - I was only checking if it was defined instead of checking if it is defined but None.

Try v0.1.1-b2.

droans avatar Aug 04 '25 16:08 droans

Adding some additional guards around the potential None values in media_item.album and image seems to clear up the exceptions and shows me a queue!

  if 'album' in media and media['album'] is not None:
    media_album = media['album']
    media_album_name = media_album.get('name')
  else:
    media_album_name = ''
  media_content_id = media['uri']
  if 'image' in queue_item and queue_item['image'] is not None:
    img = queue_item['image']
    media_image = img.get('path')
  else:
    media_image = ''
Image

Assuming it's not normal to be missing, is there any reason you can think of that I'm not seeing album or image information from the queue? My call to play the media is:

action: media_player.play_media
data:
  media_content_id: spotify:album:4DVBJPJyizvHfJQt5pYaCa
  media_content_type: album
target:
  entity_id: media_player.portable

jasongillis avatar Aug 04 '25 16:08 jasongillis

Assuming it's not normal to be missing, is there any reason you can think of that I'm not seeing album or image information from the queue? My call to play the media is:

action: media_player.play_media data: media_content_id: spotify:album:4DVBJPJyizvHfJQt5pYaCa media_content_type: album target: entity_id: media_player.portable

I don't think the way you're calling it is the issue. If you use music_assistant.play_media with the same media_content_id, it returns the same issue.

From a quick bit of testing, it seems that the Spotify provider won't provide any album information when you directly play an album. If I try it with a different provider or via a playlist, it will pull that information just fine.

droans avatar Aug 04 '25 16:08 droans

Got it. Thanks for digging in to help fix this issue!

The 0.2.0b2 release seems to have cleared this up. I can see the queue and manage items in it (delete, move, etc). Seems to all be working.

It's nice being able to see a queue for the mass players. Thanks for creating the card and queue.

jasongillis avatar Aug 04 '25 16:08 jasongillis

Glad to hear!

v0.2.0 has a lot of changes. It uses a controller to reduce calls to Music Assistant - instead of sending the request each time the get_queue service is called, it sends the requests when the integration is first loaded and then sends additional requests when Music Assistant reports that the queues or players have changed. v0.2.0 also adds now sends events to HA with the type mass_queue for the changes which can be used in automations.

droans avatar Aug 04 '25 16:08 droans