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.34k stars 49 forks source link

"Failed to Connect" when adding to Home Assistant #2574

Closed seve-martinez closed 3 months ago

seve-martinez commented 3 months 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.2

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

The problem

When trying to add Music Assistant server to Home Assistant, I get an ambiguous "Failed to connect" error message.

What I have verified:

When I restart Home Assistant, the MA server will show up in the "discovered" section with the proper url and port. However, clicking submit returns the same error.

Setup Main OS: Fedora CoreOS

Upon restart: Screenshot 2024-07-05 at 4 27 36 PM

Manual addition: Screenshot 2024-07-05 at 4 27 57 PM

How to reproduce

Spin up HA container

podman run --name home-assistant -p 8123:8123 --cap-add=NET_RAW --cap-add=NET_ADMIN -v ha_config:/config:Z homeassistant/home-assistant

Spin up MA container podman run -d --network host --privileged -v mass:/data ghcr.io/music-assistant/server

Add HACS to HA:


// Enter container
$ podman exec -it home-assistant /bin/bash

// Add HACS
$ wget -O - https://get.hacs.xyz | bash -

Add MA

Music Providers

NA

Player Providers

NA

Full log output

log.txt

Additional information

digging into the home-assistant logs i found this stack trace:

2024-07-05 22:49:26.511 ERROR (MainThread) [custom_components.mass] Unexpected exception
Traceback (most recent call last):
  File "/config/custom_components/mass/config_flow.py", line 72, in async_step_manual
    self.server_info = await get_server_info(self.hass, user_input[CONF_URL])
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/mass/config_flow.py", line 37, in get_server_info
    async with MusicAssistantClient(
               ^^^^^^^^^^^^^^^^^^^^^
  File "/config/deps/lib/python3.12/site-packages/music_assistant/client/client.py", line 59, in __init__
    self.connection = WebsocketsConnection(server_url, aiohttp_session)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/deps/lib/python3.12/site-packages/music_assistant/client/connection.py", line 40, in __init__
    self.ws_server_url = get_websocket_url(server_url)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/deps/lib/python3.12/site-packages/music_assistant/client/connection.py", line 28, in get_websocket_url
    raise RuntimeError(msg)
RuntimeError: homeassistant.local:8095 is not a valid url
2024-07-05 22:49:27.171 ERROR (MainThread) [custom_components.mass] Unexpected exception
Traceback (most recent call last):
  File "/config/custom_components/mass/config_flow.py", line 72, in async_step_manual
    self.server_info = await get_server_info(self.hass, user_input[CONF_URL])
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/mass/config_flow.py", line 37, in get_server_info
    async with MusicAssistantClient(
               ^^^^^^^^^^^^^^^^^^^^^
  File "/config/deps/lib/python3.12/site-packages/music_assistant/client/client.py", line 59, in __init__
    self.connection = WebsocketsConnection(server_url, aiohttp_session)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/deps/lib/python3.12/site-packages/music_assistant/client/connection.py", line 40, in __init__
    self.ws_server_url = get_websocket_url(server_url)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/deps/lib/python3.12/site-packages/music_assistant/client/connection.py", line 28, in get_websocket_url
    raise RuntimeError(msg)
RuntimeError: homeassistant.local:8095 is not a valid url
2024-07-05 22:49:36.221 ERROR (MainThread) [custom_components.mass] Unexpected exception
Traceback (most recent call last):
  File "/config/custom_components/mass/config_flow.py", line 72, in async_step_manual
    self.server_info = await get_server_info(self.hass, user_input[CONF_URL])
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/mass/config_flow.py", line 37, in get_server_info
    async with MusicAssistantClient(
               ^^^^^^^^^^^^^^^^^^^^^
  File "/config/deps/lib/python3.12/site-packages/music_assistant/client/client.py", line 59, in __init__
    self.connection = WebsocketsConnection(server_url, aiohttp_session)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/deps/lib/python3.12/site-packages/music_assistant/client/connection.py", line 40, in __init__
    self.ws_server_url = get_websocket_url(server_url)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/deps/lib/python3.12/site-packages/music_assistant/client/connection.py", line 28, in get_websocket_url
    raise RuntimeError(msg)
RuntimeError: 192.168.1.149:8095 is not a valid url
2024-07-05 22:49:39.203 ERROR (MainThread) [custom_components.mass] Unexpected exception
Traceback (most recent call last):
  File "/config/custom_components/mass/config_flow.py", line 72, in async_step_manual
    self.server_info = await get_server_info(self.hass, user_input[CONF_URL])
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/mass/config_flow.py", line 37, in get_server_info
    async with MusicAssistantClient(
               ^^^^^^^^^^^^^^^^^^^^^
  File "/config/deps/lib/python3.12/site-packages/music_assistant/client/client.py", line 59, in __init__
    self.connection = WebsocketsConnection(server_url, aiohttp_session)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/deps/lib/python3.12/site-packages/music_assistant/client/connection.py", line 40, in __init__
    self.ws_server_url = get_websocket_url(server_url)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/deps/lib/python3.12/site-packages/music_assistant/client/connection.py", line 28, in get_websocket_url
    raise RuntimeError(msg)
RuntimeError: 192.168.1.149 is not a valid url

Which originates here: https://github.com/music-assistant/server/blob/main/music_assistant/client/connection.py#L26 I don't know why the http:// is getting stripped.

What version of Home Assistant Core are your running

2024.7.0

What type of installation are you running?

Home Assistant Container

On what type of hardware are you running?

Linux

seve-martinez commented 3 months ago

Turns out this was an issue with CoreOS and podman. Podman does some dark magic with networking and requires containers to be in a pod to communicate. Even if you put them on the same bridge network when starting them, it still won't work.