Remove concurrent heartbeat pings on the same MPD client

- idle() and periodic ping() on one connection can cause churn/wakeups

- Normalized mixrampdb == "nan" to 0
This commit is contained in:
Götz 2026-02-28 19:01:56 -05:00
parent 897cb383eb
commit 9b910cd991
2 changed files with 4 additions and 8 deletions

View file

@ -17,10 +17,13 @@ def to_queue(mpd: MpdState) -> Queue:
def to_mixramp(mpd: MpdState) -> MixRamp: def to_mixramp(mpd: MpdState) -> MixRamp:
delay = mpd.status.get("mixrampdelay", 0) delay = mpd.status.get("mixrampdelay", 0)
db = mpd.status.get("mixrampdb", 0)
if delay == "nan": if delay == "nan":
delay = 0 delay = 0
if db == "nan":
db = 0
return MixRamp( return MixRamp(
db=float(mpd.status.get("mixrampdb", 0)), db=float(db),
delay=float(delay), delay=float(delay),
) )

View file

@ -11,7 +11,6 @@ from ..playback import Playback
from ..playback.state import PlaybackState from ..playback.state import PlaybackState
from ..player import Player from ..player import Player
from ..song_receiver import Receiver from ..song_receiver import Receiver
from ..tools.asyncio import run_background_task
from .artwork_cache import MpdArtworkCache from .artwork_cache import MpdArtworkCache
from .convert.to_playback import to_playback from .convert.to_playback import to_playback
from .types import MpdState from .types import MpdState
@ -42,12 +41,6 @@ class MpdStateListener(Player):
print("Authorising to MPD with your password...") print("Authorising to MPD with your password...")
await self.client.password(conf.password.get_secret_value()) await self.client.password(conf.password.get_secret_value())
print(f"Connected to MPD v{self.client.mpd_version}") print(f"Connected to MPD v{self.client.mpd_version}")
run_background_task(self.heartbeat())
async def heartbeat(self) -> None:
while True:
await self.client.ping()
await asyncio.sleep(10)
async def refresh(self) -> None: async def refresh(self) -> None:
await self.update_receivers() await self.update_receivers()