Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HA: Using media_player.join results in unusual data in media_player.group_members #3651

Open
1 task done
msm595 opened this issue Mar 2, 2025 · 2 comments · May be fixed by home-assistant/core#139805
Open
1 task done
Labels

Comments

@msm595
Copy link

msm595 commented Mar 2, 2025

What version of Music Assistant has the issue?

2.4.0

Have you tried everything in the Troubleshooting FAQ and reviewed the Open and Closed Issues and Discussions to resolve this yourself?

  • Yes

The problem

The MA integration in HA seems to be incorrectly reporting the group_members attribute for media_player entities when using temporary sync groups. These group_members are listed in alphabetical order instead of being listed with the "master" player in the first position of this list.

Here are two different media player cards implementations, both of which check the first member of the media_player entity's group_members attribute to determine if a player is the "master" one in a group:

  1. custom-sonos-card aka maxi-media-player
  2. mini-media-player

Because of this incorrect listing, both cards show buggy or incorrect information when trying to group players or play media for a group.

How to reproduce

Main Reproduction Steps

  1. Join two Sonos players to Music Assistant
  2. Name one "Bar" and the other "Pizza Oven". The names do not matter, just make sure it is clear which one comes first alphabetically.
  3. Set up the MA integration in HA.
  4. Use MA to start playing music on "Pizza Oven" (the one that comes later alphabetically), then add "Bar" using the checkbox in MA.
    Image
  5. Set up maxi-media-player in HA with the two entities:
      type: custom:maxi-media-player
      sections:
        - player
        - volumes
        - grouping
        - groups
      startSection: player
      entities:
        - media_player.bar
        - media_player.pizza_oven
      entityId: media_player.pizza_oven
      adjustVolumeRelativeToMainPlayer: true
      hidePlayerControlPowerButton: true
      showAudioInputFormat: true
      hideVolumeCogwheel: true
  6. Observe maxi-media-player refuse to show or select the "Pizza Oven" source:
    Image
  7. Observe maxi-media-player refuse to show media_player.pizza_oven in it's join/unjoin page:
    Image
  8. Observe in HA's developer tools that the value of media_player.pizza_oven's group_members attribute is media_player.bar, media_player.pizza_oven (master is last) instead of media_player.pizza_oven, media_player.bar (master player first in list).

Additional Errors

The above demonstrates the weirdness that occurs when the "master" player is not listed first in the group_members list. So when we set up conditions in our favor, such that the alphabetically listing also has the "master" player first, I will show the intended behavior.

Though there is still one issue in this case as well.

  1. Join two Sonos players to Music Assistant
  2. Name one "Bar" and the other "Pizza Oven". The names do not matter, just make sure it is clear which one comes first alphabetically.
  3. Set up the MA integration in HA.
  4. Use MA to start playing music on "Bar" (the one that comes first alphabetically), then add "Pizza Oven" using the checkbox in MA.
    Image
  5. Set up maxi-media-player in HA with the two entities:
      type: custom:maxi-media-player
      sections:
        - player
        - volumes
        - grouping
        - groups
      startSection: player
      entities:
        - media_player.bar
        - media_player.pizza_oven
      entityId: media_player.bar
      adjustVolumeRelativeToMainPlayer: true
      hidePlayerControlPowerButton: true
      showAudioInputFormat: true
      hideVolumeCogwheel: true
  6. Observe that maxi-media-player does allow you to control the "Bar" media player and additionally shows that "Pizza Oven" is synced as well:
    Image
  7. But observe on the join/unjoin page that "Pizza Oven" is listed twice!
    Image
  8. Additionally observe that the value of media_player.bar's group_members attribute is an empty string instead of media_player.pizza_oven, media_player.bar (showing bar is in a group, but not the master player).

Music Providers

In this case, I was testing out with the Plex Music Provider, but the error also occurs when no music is playing or queued at all. The issue is a data syncing issue with Home Assistant.

Player Providers

I've tried this with the Sonos player provider only. Unfortunately I do not have access to other players. As stated, this was tested using Temporary Sync groups.

Full log output

N/A

Additional information

The reproduction steps show the problem when playback is initiated in MA's UI. But I have observed this very same incorrect data in the entity attributes when using the media_player.join and media_player.unjoin actions from HA as well.

What version of Home Assistant Core are your running

2025.2.5

What type of installation are you running?

Home Assistant Container

On what type of hardware are you running?

Linux

@msm595 msm595 added the triage label Mar 2, 2025
@msm595
Copy link
Author

msm595 commented Mar 2, 2025

To follow up, I've done some additional research in other Home Assistant integrations.

For issue one, leaders not being first in the group_members list:

  1. HEOS reports back the group_members with the lead player first: https://github.com/home-assistant/core/blob/220509fd6c55b9f0400539bdb7ffec536504ae04/homeassistant/components/heos/media_player.py#L204
  2. So does linkplay: https://github.com/home-assistant/core/blob/220509fd6c55b9f0400539bdb7ffec536504ae04/homeassistant/components/linkplay/media_player.py#L320-L322
  3. And soundtouch: https://github.com/home-assistant/core/blob/220509fd6c55b9f0400539bdb7ffec536504ae04/homeassistant/components/soundtouch/media_player.py#L344-L345

For issue two, non-leaders showing an empty group_members list:

  1. Sonos reports back a populated group_members list for players that are not the "master" player: https://github.com/home-assistant/core/blob/dev/homeassistant/components/sonos/speaker.py#L916-L926
  2. As does bang_olufsen: https://github.com/home-assistant/core/blob/220509fd6c55b9f0400539bdb7ffec536504ae04/homeassistant/components/bang_olufsen/media_player.py#L489-L506

This leads me to believe that the MusicAssistant integration is currently not in line with other media_player integrations. While this may not be a strict requirement of how group_members must be populated, I would still consider this a compatibility bug due to the strong precedence of many other integrations following this pattern.

@msm595
Copy link
Author

msm595 commented Mar 5, 2025

I've attempted a fix PR, feel free to modify or change it: home-assistant/core#139805

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant