Skip to content

Commit

Permalink
Dynamically update poll interval for sonos s1 speakers
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Oct 24, 2024
1 parent 720e13e commit f2c6500
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions music_assistant/server/providers/sonos_s1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from music_assistant.common.models.enums import (
ConfigEntryType,
PlayerFeature,
PlayerState,
PlayerType,
ProviderFeature,
)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f2c6500

Please sign in to comment.