Update __main__.py
Add volume max percentage and config for volume sync.
This commit is contained in:
@@ -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).
|
||||||
|
if getattr(config.audio, "volume_sync", False):
|
||||||
try:
|
try:
|
||||||
loop.create_task(
|
loop.create_task(
|
||||||
ensure_output_volume(
|
ensure_output_volume(
|
||||||
volume=preferences.volume_level,
|
volume=preferences.volume_level,
|
||||||
output_device=config.audio.output_device,
|
output_device=config.audio.output_device,
|
||||||
|
max_volume_percent=getattr(config.audio, "max_volume_percent", 100),
|
||||||
attempts=20,
|
attempts=20,
|
||||||
delay_seconds=0.5,
|
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(
|
||||||
|
|||||||
Reference in New Issue
Block a user