Update __main__.py

Add volume max percentage and config for volume sync.
This commit is contained in:
imonlinux
2026-01-06 13:37:00 -08:00
committed by GitHub
parent 6866358dfe
commit 010e5447df
+14 -10
View File
@@ -169,17 +169,21 @@ async def main() -> None:
# --- 5b. Sync OS sink volume to persisted volume --- # --- 5b. Sync OS sink volume to persisted volume ---
# mpv's per-player volume is kept at 100% and ducking is handled within mpv. # mpv's per-player volume is kept at 100% and ducking is handled within mpv.
# The user-visible "volume" in HA maps to the OS output volume (PipeWire/Pulse/ALSA). # The user-visible "volume" in HA maps to the OS output volume (PipeWire/Pulse/ALSA).
try: if getattr(config.audio, "volume_sync", False):
loop.create_task( try:
ensure_output_volume( loop.create_task(
volume=preferences.volume_level, ensure_output_volume(
output_device=config.audio.output_device, volume=preferences.volume_level,
attempts=20, output_device=config.audio.output_device,
delay_seconds=0.5, max_volume_percent=getattr(config.audio, "max_volume_percent", 100),
attempts=20,
delay_seconds=0.5,
)
) )
) except Exception:
except Exception: _LOGGER.exception("Failed to schedule output volume sync")
_LOGGER.exception("Failed to schedule output volume sync") else:
_LOGGER.debug("Output volume sync disabled (audio.volume_sync=false)")
# --- 6. Create Server State --- # --- 6. Create Server State ---
state = _create_server_state( state = _create_server_state(