Fix Sonos S1 not reconnecting after having gone offline. (#2874)
authorMarvin Schenkel <marvinschenkel@gmail.com>
Tue, 23 Dec 2025 15:44:10 +0000 (16:44 +0100)
committerGitHub <noreply@github.com>
Tue, 23 Dec 2025 15:44:10 +0000 (16:44 +0100)
music_assistant/providers/sonos_s1/player.py

index 1d4137aec90485d6c4328fccb8478ea48515177e..36036ee52ba2f70476e7125539209071d2327078 100644 (file)
@@ -280,7 +280,9 @@ class SonosPlayer(Player):
             self._attr_volume_level = self.soco.volume
             self._attr_volume_muted = self.soco.mute
 
-        await asyncio.to_thread(_poll)
+        await self._check_availability()
+        if self._attr_available:
+            await asyncio.to_thread(_poll)
 
     @soco_error()
     def poll_media(self) -> None:
@@ -317,6 +319,20 @@ class SonosPlayer(Player):
         )
         self.update_player()
 
+    async def _check_availability(self) -> None:
+        """Check if the player is still available."""
+        try:
+            await asyncio.to_thread(self.ping)
+            self._speaker_activity("ping")
+        except SonosUpdateError:
+            if not self._attr_available:
+                return
+            self.logger.warning(
+                "No recent activity and cannot reach %s, marking unavailable",
+                self.display_name,
+            )
+            await self.offline()
+
     @soco_error()
     def ping(self) -> None:
         """Test device availability. Failure will raise SonosUpdateError."""