Enhance volume persistence with logging

Add logging for volume persistence and conditionally skip saving if unchanged.
This commit is contained in:
Omar Amin authored and GitHub committed 2026-02-22 00:43:32 +02:00
1 parent 981a786a46
commit c81a707c6a
1 file changed
+4
+4
View File
@@ -110,14 +110,18 @@ class ServerState:
def persist_volume(self, volume: float) -> None:
"""Persist the normalized media volume (0.0 - 1.0)."""
clamped_volume = max(0.0, min(1.0, volume))
_LOGGER.debug(f"persist_volume called: new={clamped_volume}, current={self.volume}, prefs={self.preferences.volume}")
if (
abs(self.volume - clamped_volume) < 0.0001
and self.preferences.volume is not None
and abs(self.preferences.volume - clamped_volume) < 0.0001
):
_LOGGER.debug("Skipping save - volume unchanged")
return
self.volume = clamped_volume
self.preferences.volume = clamped_volume
_LOGGER.info(f"Saving volume {clamped_volume} to {self.preferences_path}")
self.save_preferences()
_LOGGER.info(f"Volume saved successfully")