async def set_name(name: str = None) -> str:
    """
    Change the name by writing /etc/machine-info and then calling setup_name

    :param name: The name to set. If ``None``, read it from /etc/machine-info
    :returns: The name that was set. This may be different from ``name``, if
              ``name`` was none or if the pretty hostname could not be written
    """

    if name:
        checked_name = name
        try:
            _update_pretty_hostname(checked_name)
        except OSError:
            LOG.exception("Could not set pretty hostname")
            checked_name = get_name()
    else:
        checked_name = get_name()

    async with _BUS_LOCK:
        await asyncio.get_event_loop().run_in_executor(
            None, _set_name_future, checked_name)
    return checked_name
Change the name by writing /etc/machine-info and then calling setup_name

    :param name: The name to set. If ``None``, read it from /etc/machine-info
    :returns: The name that was set. This may be different from ``name``, if
              ``name`` was none or if the pretty hostname could not be written