MusicCast: Fix ungroup & discovery (#2545)
authorFabian Munkes <105975993+fmunkes@users.noreply.github.com>
Sat, 25 Oct 2025 13:15:33 +0000 (15:15 +0200)
committerGitHub <noreply@github.com>
Sat, 25 Oct 2025 13:15:33 +0000 (15:15 +0200)
music_assistant/providers/musiccast/player.py
music_assistant/providers/musiccast/provider.py

index 213886008f16d40cb16fd5d5432d3b166ded4f50..fab8ce5f17d6c9cdfe9d27a4b232babd08a4d964 100644 (file)
@@ -527,9 +527,18 @@ class MusicCastPlayer(Player):
     ) -> None:
         """Set multiple members.
 
-        If we are a server, this is called.
-        We can ignore removed devices, these are handled via ungroup individually.
+        This function is called on the server.
         """
+        # Removing players
+        if player_ids_to_remove:
+            for player_id in player_ids_to_remove:
+                if player := self.mass.players.get(player_id):
+                    assert isinstance(player, MusicCastPlayer)  # for type checking
+                    await player.ungroup()
+
+        # Adding players
+        if not player_ids_to_add:
+            return
         children: set[str] = set()  # set[ma_player_id]
         children_zones: list[str] = []  # list[ma_player_id]
         player_ids_to_add = [] if player_ids_to_add is None else player_ids_to_add
index a2416d1e6464490e9c522a9e4687109e4ffa2f5e..632ae75c511c261c6886e1ef90ab7db08ac29148 100644 (file)
@@ -126,14 +126,15 @@ class MusicCastProvider(PlayerProvider):
             device_info = await self.mass.http_session.get(
                 f"http://{device_ip}/{MC_DEVICE_INFO_ENDPOINT}", raise_for_status=True
             )
+            device_info_json = await device_info.json()
         except ClientError:
             # typical Errors are
             # ClientResponseError -> raise_for_status
             # ClientConnectorError -> unable to connect/ not existing/ timeout
+            # ContentTypeError -> device returns something, but is not json
             # but we can use the base exception class, as we only check
             # if the device is suitable
             return
-        device_info_json = await device_info.json()
         device_id = device_info_json.get("device_id")
         if device_id is None:
             return