def METHOD_NAME(device: Optional[Union[str, Device]] = None) -> Device:
    """
    Sanitizes a device or device identifier, i.e. checks whether it is already an instance of :class:`~heat.core.device.Device` or a string with
    known device identifier and maps it to a proper :class:`~heat.core.device.Device`.
    Parameters
    ----------
    device : str or Device, optional
        The device to be sanitized
    Raises
    ------
    ValueError
        If the given device id is not recognized
    """
    if device is None:
        return get_device()
    if isinstance(device, Device):
        return device
    try:
        return __device_mapping[device.strip().lower()]
    except (AttributeError, KeyError, TypeError):
        raise ValueError(f'Unknown device, must be one of {", ".join(__device_mapping.keys())}')