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:
)
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."""