"""WizardKit: Audio test functions"""
# vim: sts=2 sw=2 ts=2

import logging

from wk.exe import run_program
from wk.std import PLATFORM


# STATIC VARIABLES
LOG = logging.getLogger(__name__)


# Functions
def audio_test() -> None:
  """Run an OS-specific audio test."""
  if PLATFORM == 'Linux':
    audio_test_linux()


def audio_test_linux() -> None:
  """Run an audio test using amixer and speaker-test."""
  LOG.info('Audio Test')

  # Set volume
  for source in ('Master', 'PCM'):
    cmd = f'amixer -q set "{source}" 80% unmute'.split()
    run_program(cmd, check=False)

  # Run audio tests
  for mode in ('pink', 'wav'):
    cmd = f'speaker-test -c 2 -l 1 -t {mode}'.split()
    run_program(cmd, check=False, pipe=False)


if __name__ == '__main__':
  print("This file is not meant to be called directly.")
