# Path: kano_settings/config_file.py
# def get_setting(variable):
# 
#     try:
#         value = read_json(settings_file)[variable]
#     except Exception:
#         if variable not in DEFAULTS:
#             logger.info("Defaults not found for variable: {}".format(variable))
#         value = DEFAULTS[variable]
#     return value
# 
# def set_setting(variable, value):
# 
#     if username == 'root':
#         return
# 
#     logger.debug(u"config_file / set_setting: {} {}".format(variable, value))
# 
#     data = read_json(settings_file)
#     if not data:
#         data = dict()
# 
#     data[variable] = value
#     write_json(settings_file, data)
#     chown_path(settings_file)
# 
# Path: kano_settings/boot_config.py
# def set_config_value(self, name, value=None, config_filter=Filter.ALL):
#     self.set_state_writable()
#     self.temp_config.set_value(name, value, config_filter)
# 
# def end_config_transaction():
#     _trans().close()
# 
# Path: kano_settings/paths.py
# ASOUND_CONF_PATH = join(ASOUND_CONF_BASE_PATH, ASOUND_CONF_NAME)


from kano.utils.shell import run_cmd, run_bg
from kano.logging import logger
from kano_peripherals.wrappers.detection import is_pi_hat_plugged
from kano_settings.config_file import get_setting, set_setting
from kano_settings.boot_config import set_config_value, end_config_transaction
from kano_settings.paths import ASOUND_CONF_PATH
        from kano_settings.system.display import get_edid
    # Set audio path in amixer
    o, e, rc = run_cmd(amixer_cmd)
    if rc:
        logger.warn("error from amixer: {} {} {}".format(o, e, rc))

    # trigger alsa-store to store the path in /var/lib/alsa/asound.state
    o, e, rc = run_cmd(store_cmd)
    if rc:
        logger.warn("error from alsa-store: {} {} {}".format(o, e, rc))

    set_setting('Audio', config)
    return config


# Returns is_HDMI = True or False
def is_HDMI():
    # Find the audio setting
    amixer_string, e, rc = run_cmd(amixer_get_cmd)
    if rc:
        logger.warn("error from amixer: {} {} {}".format(amixer_string, e, rc))

    if amixer_string.find(hdmi_string) != -1:
        # Make sure config file is up to date
        if get_setting('Audio') != _("HDMI"):
            set_setting('Audio', _("HDMI"))
        return True

    # Default to Analogue
    else:
        # Make sure config file is up to date

# Path: kano_settings/config_file.py
# def get_setting(variable):
# 
#     try:
#         value = read_json(settings_file)[variable]
#     except Exception:
#         if variable not in DEFAULTS:
#             logger.info("Defaults not found for variable: {}".format(variable))
#         value = DEFAULTS[variable]
#     return value
# 
# def set_setting(variable, value):
# 
#     if username == 'root':
#         return
# 
#     logger.debug(u"config_file / set_setting: {} {}".format(variable, value))
# 
#     data = read_json(settings_file)
#     if not data:
#         data = dict()
# 
#     data[variable] = value
#     write_json(settings_file, data)
#     chown_path(settings_file)
# 
# Path: kano_settings/boot_config.py
# def set_config_value(self, name, value=None, config_filter=Filter.ALL):
#     self.set_state_writable()
#     self.temp_config.set_value(name, value, config_filter)
# 
# def end_config_transaction():
#     _trans().close()
# 
# Path: kano_settings/paths.py
# ASOUND_CONF_PATH = join(ASOUND_CONF_BASE_PATH, ASOUND_CONF_NAME)


# Path: kano_settings/system/audio.py
from kano.utils.shell import run_cmd, run_bg
from kano.logging import logger
from kano_peripherals.wrappers.detection import is_pi_hat_plugged
from kano_settings.config_file import get_setting, set_setting
from kano_settings.boot_config import set_config_value, end_config_transaction
from kano_settings.paths import ASOUND_CONF_PATH
        from kano_settings.system.display import get_edid

    # Set audio path in amixer
    o, e, rc = run_cmd(amixer_cmd)
    if rc:
        logger.warn("error from amixer: {} {} {}".format(o, e, rc))

    # trigger alsa-store to store the path in /var/lib/alsa/asound.state
    o, e, rc = run_cmd(store_cmd)
    if rc:
        logger.warn("error from alsa-store: {} {} {}".format(o, e, rc))

    set_setting('Audio', config)
    return config


# Returns is_HDMI = True or False
def is_HDMI():
    # Find the audio setting
    amixer_string, e, rc = run_cmd(amixer_get_cmd)
    if rc:
        logger.warn("error from amixer: {} {} {}".format(amixer_string, e, rc))

    if amixer_string.find(hdmi_string) != -1:
        # Make sure config file is up to date
        if get_setting('Audio') != _("HDMI"):
            set_setting('Audio', _("HDMI"))
        return True

    # Default to Analogue
    else:
        # Make sure config file is up to date

        if get_setting('Audio') != _("Analogue"):