def create_default_config(config_dir, detect_location=True):
    """Create a default configuration file in given configuration directory.

    Return path to new config file if success, None if failed.
    """
    config_path = os.path.join(config_dir, YAML_CONFIG_FILE)

    info = {attr: default for attr, default, _, _ in DEFAULT_CONFIG}

    location_info = detect_location and loc_util.detect_location_info()

    if location_info:
        if location_info.use_fahrenheit:
            info[CONF_TEMPERATURE_UNIT] = 'F'

        for attr, default, prop, _ in DEFAULT_CONFIG:
            if prop is None:
                continue
            info[attr] = getattr(location_info, prop) or default

    # Writing files with YAML does not create the most human readable results
    # So we're hard coding a YAML template.
    try:
        with open(config_path, 'w') as config_file:
            config_file.write("homeassistant:\n")

            for attr, _, _, description in DEFAULT_CONFIG:
                if info[attr] is None:
                    continue
                elif description:
                    config_file.write("  # {}\n".format(description))
                config_file.write("  {}: {}\n".format(attr, info[attr]))

            config_file.write("\n")

            for component, description in DEFAULT_COMPONENTS.items():
                config_file.write("# {}\n".format(description))
                config_file.write("{}\n\n".format(component))

        return config_path

    except __HOLE__:
        print('Unable to create default configuration file', config_path)
        return None
dataset/ETHPy150Open home-assistant/home-assistant/homeassistant/config.py/create_default_config