Skip to content

Commit

Permalink
Add advanced networking (list of IPs) to Sonos S1 provider (#1988)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcblum authored Mar 7, 2025
1 parent 935d53a commit 0af5a7c
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions music_assistant/providers/sonos_s1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@
from music_assistant_models.errors import PlayerCommandFailed, PlayerUnavailableError
from music_assistant_models.player import DeviceInfo, Player, PlayerMedia
from requests.exceptions import RequestException
from soco import SoCo, events_asyncio, zonegroupstate
from soco import config as soco_config
from soco import events_asyncio, zonegroupstate
from soco.discovery import discover, scan_network

from music_assistant.constants import (
CONF_CROSSFADE,
CONF_ENTRY_CROSSFADE,
CONF_ENTRY_FLOW_MODE_HIDDEN_DISABLED,
CONF_ENTRY_HTTP_PROFILE_FORCED_1,
CONF_ENTRY_MANUAL_DISCOVERY_IPS,
CONF_ENTRY_OUTPUT_CODEC,
VERBOSE_LOG_LEVEL,
create_sample_rates_config_entry,
Expand All @@ -47,7 +48,6 @@
if TYPE_CHECKING:
from music_assistant_models.config_entries import ProviderConfig
from music_assistant_models.provider import ProviderManifest
from soco.core import SoCo

from music_assistant.mass import MusicAssistant
from music_assistant.models import ProviderInstanceType
Expand Down Expand Up @@ -120,6 +120,7 @@ async def get_config_entries(
category="advanced",
required=False,
),
CONF_ENTRY_MANUAL_DISCOVERY_IPS,
)


Expand Down Expand Up @@ -365,6 +366,25 @@ async def discover_players(self) -> None:
if self._discovery_running:
return

# Handle config option for manual IP's
manual_ip_config = cast(
list[str], self.config.get_value(CONF_ENTRY_MANUAL_DISCOVERY_IPS.key)
)
for ip_address in manual_ip_config:
try:
player = SoCo(ip_address)
self._add_player(player)
except RequestException as err:
# player is offline
self.logger.debug("Failed to add SonosPlayer %s: %s", player, err)
except Exception as err:
self.logger.warning(
"Failed to add SonosPlayer %s: %s",
player,
err,
exc_info=err if self.logger.isEnabledFor(10) else None,
)

allow_network_scan = self.config.get_value(CONF_NETWORK_SCAN)
if not (household_id := self.config.get_value(CONF_HOUSEHOLD_ID)):
household_id = "Sonos"
Expand Down

0 comments on commit 0af5a7c

Please sign in to comment.