import json


def find_dtoverlay_config(variable_list):
    """
    Find value and id of BALENA_HOST_CONFIG_dtoverlay or RESIN_HOST_CONFIG_dtoverlay.
    Return None if it doesn't exist.
    """
    current_dt_overlay = None
    dt_overlay_var_id = None

    for variable in variable_list:
        if variable["name"] in ["BALENA_HOST_CONFIG_dtoverlay", "RESIN_HOST_CONFIG_dtoverlay"]:
            dt_overlay_var_id = str(variable["id"])
            # If contains quotes, parse as a JSON lists
            if variable["value"].startswith('"') and variable["value"].endswith('"'):
                current_dt_overlay = set(json.loads("[" + variable["value"] + "]"))
            else:
                current_dt_overlay = set([variable["value"]])

    return current_dt_overlay, dt_overlay_var_id