From f2c650063f0933b5efef4b97e5adcea304fab570 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Thu, 24 Oct 2024 14:33:12 +0200 Subject: [PATCH] Dynamically update poll interval for sonos s1 speakers --- music_assistant/server/providers/sonos_s1/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/music_assistant/server/providers/sonos_s1/__init__.py b/music_assistant/server/providers/sonos_s1/__init__.py index c3ab38dd9..e16042fa5 100644 --- a/music_assistant/server/providers/sonos_s1/__init__.py +++ b/music_assistant/server/providers/sonos_s1/__init__.py @@ -32,6 +32,7 @@ from music_assistant.common.models.enums import ( ConfigEntryType, PlayerFeature, + PlayerState, PlayerType, ProviderFeature, ) @@ -215,6 +216,7 @@ async def cmd_play(self, player_id: str) -> None: ) return await asyncio.to_thread(sonos_player.soco.play) + sonos_player.mass_player.poll_interval = 5 self.mass.call_later(2, sonos_player.poll_speaker) async def cmd_pause(self, player_id: str) -> None: @@ -296,6 +298,7 @@ async def play_media( didl_metadata = create_didl_metadata(media) await asyncio.to_thread(sonos_player.soco.play_uri, media.uri, meta=didl_metadata) self.mass.call_later(2, sonos_player.poll_speaker) + sonos_player.mass_player.poll_interval = 5 async def enqueue_next_media(self, player_id: str, media: PlayerMedia) -> None: """Handle enqueuing of the next queue item on the player.""" @@ -340,6 +343,13 @@ async def poll_player(self, player_id: str) -> None: if player_id not in self.sonosplayers: return sonos_player = self.sonosplayers[player_id] + # dynamically change the poll interval + if sonos_player.mass_player.state == PlayerState.PLAYING: + sonos_player.mass_player.poll_interval = 5 + elif sonos_player.mass_player.powered: + sonos_player.mass_player.poll_interval = 20 + else: + sonos_player.mass_player.poll_interval = 60 try: # the check_poll logic will work out what endpoints need polling now # based on when we last received info from the device