Skip to content

Commit

Permalink
Fix empty players list in config (#1062)
Browse files Browse the repository at this point in the history
ensure instance id for player provider
  • Loading branch information
marcelveldt authored Feb 3, 2024
1 parent 1d651db commit e00d99e
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 21 deletions.
18 changes: 5 additions & 13 deletions music_assistant/server/controllers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,6 @@ async def setup(self) -> None:
"""Async initialize of controller."""
await self._load()
self.initialized = True
#### temp fix issue introduced in b89 ##########
# TODO: remove after b92
final_player_configs = {}
for player_id, player_conf in self.get(CONF_PLAYERS, {}).items():
if "provider" in player_conf:
final_player_configs[player_id] = player_conf
self.set(CONF_PLAYERS, final_player_configs)
#### end of temp fix ############################

# create default server ID if needed (also used for encrypting passwords)
self.set_default(CONF_SERVER_ID, uuid4().hex)
server_id: str = self.get(CONF_SERVER_ID)
Expand All @@ -88,7 +79,6 @@ async def setup(self) -> None:
self._fernet = Fernet(fernet_key)
config_entries.ENCRYPT_CALLBACK = self.encrypt_string
config_entries.DECRYPT_CALLBACK = self.decrypt_string

LOGGER.debug("Started.")

async def close(self) -> None:
Expand Down Expand Up @@ -322,11 +312,13 @@ async def reload_provider(self, instance_id: str) -> None:
async def get_player_configs(self, provider: str | None = None) -> list[PlayerConfig]:
"""Return all known player configurations, optionally filtered by provider domain."""
available_providers = {x.instance_id for x in self.mass.providers}
# add both domain and instance id
available_providers.update({x.domain for x in self.mass.providers})
return [
await self.get_player_config(player_id)
for player_id, raw_conf in self.get(CONF_PLAYERS, {}).items()
await self.get_player_config(raw_conf["player_id"])
for raw_conf in list(self.get(CONF_PLAYERS, {}).values())
# filter out unavailable providers
if raw_conf["provider"] in available_providers
if self.mass.get_provider(raw_conf["provider"])
# optional provider filter
and (provider in (None, raw_conf["provider"]))
]
Expand Down
2 changes: 1 addition & 1 deletion music_assistant/server/controllers/players.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ async def create_group(self, provider: str, name: str, members: list[str]) -> Pl
return await player_prov.create_group(name, members=members)
if ProviderFeature.SYNC_PLAYERS in player_prov.supported_features:
# default syncgroup implementation
return await self._create_syncgroup(provider, name, members)
return await self._create_syncgroup(player_prov.instance_id, name, members)
raise UnsupportedFeaturedException(
f"Provider {player_prov.name} does not support creating groups"
)
Expand Down
2 changes: 1 addition & 1 deletion music_assistant/server/providers/airplay/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ async def cmd_unsync(self, player_id: str) -> None:
async def _handle_player_register_callback(self, player: Player) -> None:
"""Handle player register callback from slimproto source player."""
# TODO: Can we get better device info from mDNS ?
player.provider = self.domain
player.provider = self.instance_id
player.device_info = DeviceInfo(
model="Airplay device",
address=player.device_info.address,
Expand Down
2 changes: 1 addition & 1 deletion music_assistant/server/providers/chromecast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ def _on_chromecast_discovered(self, uuid, _):
),
player=Player(
player_id=player_id,
provider=self.domain,
provider=self.instance_id,
type=PlayerType.GROUP if cast_info.is_audio_group else PlayerType.PLAYER,
name=cast_info.friendly_name,
available=False,
Expand Down
2 changes: 1 addition & 1 deletion music_assistant/server/providers/dlna/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ async def _device_discovered(self, udn: str, description_url: str) -> None:
udn=udn,
player=Player(
player_id=udn,
provider=self.domain,
provider=self.instance_id,
type=PlayerType.PLAYER,
name=udn,
available=False,
Expand Down
2 changes: 1 addition & 1 deletion music_assistant/server/providers/slimproto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ async def _handle_player_update(self, client: SlimClient) -> None:
# player does not yet exist, create it
player = Player(
player_id=player_id,
provider=self.domain,
provider=self.instance_id,
type=PlayerType.PLAYER,
name=client.name,
available=True,
Expand Down
2 changes: 1 addition & 1 deletion music_assistant/server/providers/snapcast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def _handle_player_init(self, snap_client: Snapclient) -> None:
snap_client = cast(Snapclient, self._snapserver.client(player_id))
player = Player(
player_id=player_id,
provider=self.domain,
provider=self.instance_id,
type=PlayerType.PLAYER,
name=snap_client.friendly_name,
available=True,
Expand Down
2 changes: 1 addition & 1 deletion music_assistant/server/providers/sonos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def _add_player(self, soco: SoCo) -> None:
if not (mass_player := self.mass.players.get(soco.uid)):
mass_player = Player(
player_id=soco.uid,
provider=self.domain,
provider=self.instance_id,
type=PlayerType.PLAYER,
name=soco.player_name,
available=True,
Expand Down
2 changes: 1 addition & 1 deletion music_assistant/server/providers/sonos/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def __init__(
self.mass = sonos_prov.mass
self.player_id = soco.uid
self.soco = soco
self.logger = sonos_prov.logger.getChild(soco.uid)
self.logger = sonos_prov.logger
self.household_id: str = soco.household_id
self.subscriptions: list[SubscriptionBase] = []
self.websocket: SonosWebsocket | None = None
Expand Down

0 comments on commit e00d99e

Please sign in to comment.