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

Fixed stream_ip resolution for kubernetes users #516

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion custom_components/mass/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import logging
import os
import socket
from urllib.parse import urlparse

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
Expand All @@ -11,6 +13,7 @@
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.start import async_at_start
from homeassistant.helpers.network import get_url
from music_assistant import MusicAssistant
from music_assistant.models.config import MassConfig, MusicProviderConfig
from music_assistant.models.enums import EventType, ProviderType
Expand Down Expand Up @@ -49,6 +52,15 @@
EventType.QUEUE_TIME_UPDATED,
)

def get_local_ip_from_internal_url(hass: HomeAssistant):
"""Get the stream ip address from the internal_url."""
url = get_url(hass, allow_internal=True, allow_external=False)
parsed_uri = urlparse(url)

if parsed_uri.netloc == '':
return hass.config.api.local_ip

return socket.gethostbyname(parsed_uri.netloc)

async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Set up from a config entry."""
Expand Down Expand Up @@ -95,7 +107,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
path=conf.get(CONF_FILE_DIRECTORY),
)
)
stream_ip = hass.config.api.local_ip
stream_ip = get_local_ip_from_internal_url(hass)
mass_conf = MassConfig(
database_url=f"sqlite:///{db_file}", providers=providers, stream_ip=stream_ip
)
Expand Down