Skip to content

Commit

Permalink
PR Feedback: Autoselect proxy server port, better region names, loggi…
Browse files Browse the repository at this point in the history
…ng levels
  • Loading branch information
btoconnor committed Oct 20, 2024
1 parent df0a9fa commit 35ef963
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
23 changes: 8 additions & 15 deletions music_assistant/server/providers/siriusxm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from collections.abc import AsyncGenerator, Awaitable, Sequence
from typing import TYPE_CHECKING, Any, cast

from music_assistant.common.helpers.util import select_free_port
from music_assistant.common.models.config_entries import (
ConfigEntry,
ConfigValueOption,
Expand Down Expand Up @@ -46,7 +47,6 @@
CONF_SXM_USERNAME = "sxm_email_address"
CONF_SXM_PASSWORD = "sxm_password"
CONF_SXM_REGION = "sxm_region"
CONF_SXM_PROXY_PORT = "sxm_proxy_port"


async def setup(
Expand Down Expand Up @@ -87,19 +87,12 @@ async def get_config_entries(
key=CONF_SXM_REGION,
type=ConfigEntryType.STRING,
default_value="US",
options=tuple(ConfigValueOption(x, x) for x in ("US", "CA")),
options=(
ConfigValueOption(title="United States", value="US"),
ConfigValueOption(title="Canada", value="CA"),
),
label="Region",
required=False,
),
ConfigEntry(
key=CONF_SXM_PROXY_PORT,
type=ConfigEntryType.INTEGER,
label="SXM local server port",
description="The local port for hosting the SXM proxy server",
required=True,
default_value=9999,
value=values.get(CONF_SXM_PROXY_PORT) if values else None,
category="advanced",
),
)

Expand Down Expand Up @@ -130,8 +123,6 @@ async def handle_async_init(self) -> None:
username: str = self.config.get_value(CONF_SXM_USERNAME)
password: str = self.config.get_value(CONF_SXM_PASSWORD)

bind_port: int = self.config.get_value(CONF_SXM_PROXY_PORT)

region: RegionChoice = (
RegionChoice.US if self.config.get_value(CONF_SXM_REGION) == "US" else RegionChoice.CA
)
Expand All @@ -154,6 +145,8 @@ async def handle_async_init(self) -> None:

# Set up the sxm server for streaming
bind_ip = "127.0.0.1"
bind_port = await select_free_port(8100, 9999)

self._base_url = f"{bind_ip}:{bind_port}"
http_handler = sxm.http.make_http_handler(self._client)

Expand All @@ -168,7 +161,7 @@ async def handle_async_init(self) -> None:
],
)

self.logger.info(f"SXM Proxy server running at {bind_ip}:{bind_port}")
self.logger.debug(f"SXM Proxy server running at {bind_ip}:{bind_port}")

async def unload(self) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion music_assistant/server/providers/siriusxm/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"domain": "siriusxm",
"name": "SiriusXM",
"description": "Support for the SiriusXM streaming radio provider in Music Assistant.",
"codeowners": ["@music-assistant"],
"codeowners": ["@btoconnor"],
"requirements": ["sxm==0.2.8"],
"documentation": "https://music-assistant.io/music-providers/siriusxm/",
"multi_instance": false
Expand Down

0 comments on commit 35ef963

Please sign in to comment.