music-assistant / hass-music-assistant

Turn your Home Assistant instance into a jukebox, hassle free streaming of your favorite media to Home Assistant media players.
Apache License 2.0
1.24k stars 44 forks source link

Music Assistant will not load HA plugin with Home Assistant v2024.6.2 when using Docker based Install #2582

Closed indomitableMan closed 6 days ago

indomitableMan commented 2 weeks ago

What version of Music Assistant has the issue?

2.0.7

What version of the Home Assistant Integration have you got installed?

2024.6.4

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

The problem

After following the instructions for installing Music Assistant in a Docker container, it does not seem possible to get Music Assistant to recognize Home Assistant running in a separate Docker container. (NOTE: _if players are added to Music Assistant, these players will appear in Home Assistant as media_player entities._)

How to reproduce

Unable to enable Home Assistant plugin in Music Assistant when HA and MA are running in Docker images on the same host despite setting up network communication between them. No music services or players were set up; this is an initial installation of Music Assistant with an empty /data directory.

Log message initially seen in MA is as follows: 2024-07-06 22:43:00.775 INFO (MainThread) [hass_client] Connected to Home Assistant 192.168.86.9:8123 (version 2024.6.4)

. . . however the web interface on MA never updates to show a successful authentication; the UI continuously displays the "spinning circle" and the SAVE button in MA is never enabled.

The following messages occasionally appear in the MA log during the HA plugin set up:

2024-07-06 22:49:51.554 ERROR (MainThread) [music_assistant] Error doing task: Unclosed client session
2024-07-06 22:49:51.554 ERROR (MainThread) [music_assistant] Error doing task: Task was destroyed but it is pending!
2024-07-06 22:49:51.555 ERROR (MainThread) [music_assistant] Error doing task: Unclosed client session
2024-07-06 22:49:51.555 ERROR (MainThread) [music_assistant] Error doing task: Task was destroyed but it is pending!

In an effort to troubleshoot this issue, I enabled "debug logging" in Home Assistant for the Music Assistant plug in.

The following messages appears in the HA log with Debug Logging enabled:

2024-07-06 22:50:10.464 DEBUG (MainThread) [music_assistant.client.connection] Received message:
WSMessage(type=<WSMsgType.TEXT: 1>, data='{"event":"auth_session","object_id":"R10prg5GtuA","data":"http://192.168.86.9:8123/auth/authorize?client_id=http%3A//192.168.86.9%3A8097&redirect_uri=http%3A//192.168.86.9%3A8097/callback/R10prg5GtuA&state=R10prg5GtuA"}', extra='')

2024-07-06 22:50:10.464 DEBUG (MainThread) [music_assistant.client] Received event: MassEvent(event=<EventType.AUTH_SESSION: 'auth_session'>, object_id='R10prg5GtuA', data='http://192.168.86.9:8123/auth/authorize?client_id=http%3A//192.168.86.9%3A8097&redirect_uri=http%3A//192.168.86.9%3A8097/callback/R10prg5GtuA&state=R10prg5GtuA')

Configuration Settings for the MA Container:

io.hass.platform = Core
io.hass.type = addon

Music Providers

None.

Player Providers

None.

Full log output

music-assistant-log-showing-issues.txt

Additional information

Containers are being run on a QNAP NAS running QTS v5.1.7.2770 on Container Station v3.0.7.891 (a Docker clone)

What version of Home Assistant Core are your running

2024.6.4

What type of installation are you running?

Home Assistant Container

On what type of hardware are you running?

Linux

indomitableMan commented 2 weeks ago

May be related to issue 2574 although the presentation is different.

indomitableMan commented 2 weeks ago

This behavior is also seen when trying to use Music Assistant with Home Assistant v2024.7.1 as well and is a blocker to my being able to use Music Assistant with my Home Assistant installation.

OzGav commented 2 weeks ago

Have you configured all the IP and bind addresses correctly in the MA settings for the stream and web servers?

indomitableMan commented 2 weeks ago

From the MA logs it appears that MA gets the correct IP addresses and does respond when a web browser does an HTTP request on port 8095. I suspect there are one or more issues in the web server code since the following error message appears every time a shutdown command is issued to the container running MA:

024-07-08 21:51:43.274 ERROR (MainThread) [root] Uncaught exception
Traceback (most recent call last):
  File "/usr/local/bin/mass", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/lib/python3.12/site-packages/music_assistant/__main__.py", line 214, in main
    run(
  File "/usr/local/lib/python3.12/site-packages/aiorun.py", line 370, in run
    raise pending_exception_to_raise
  File "/usr/local/lib/python3.12/site-packages/aiorun.py", line 272, in run
    shutdown_callback(loop)
  File "/usr/local/lib/python3.12/site-packages/music_assistant/__main__.py", line 204, in on_shutdown
    loop.run_until_complete(mass.stop())
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/music_assistant/server/server.py", line 175, in stop
    await self.streams.close()
  File "/usr/local/lib/python3.12/site-packages/music_assistant/server/controllers/streams.py", line 219, in close
    await self._server.close()
  File "/usr/local/lib/python3.12/site-packages/music_assistant/server/helpers/webserver.py", line 87, in close
    await self._tcp_site.stop()
          ^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'stop'
remoteassist commented 2 weeks ago

I had a same error with the MA log, there should be a popup window to login into Home Assistant to get the access token. My problem was that MA was not using the token and I had to add one in HA and put it manually in MA. image

OzGav commented 1 week ago

@indomitableMan does the solution above work for you?

McDAlexander commented 1 week ago

I ran into the same issue on my unRaid docker setup. I wound up changing Music Assistant from network type "Host" to my custom proxynet (setup based on spaceinvaderone) and then setup 2 ports into Music assistant (8095 & 8097). This somehow worked for me with my Home Assistant configuration (also an unRAID docker in the proxynet network)

OzGav commented 1 week ago

@indomitableMan we will close this soon if there is no follow-up