def _new_device_id(self, key):
        """
        Generate a new device id or return existing device id for key

        :param key: Key for device
        :type key: unicode
        :return: The device id
        :rtype: int
        """
        device_id = Id.SERVER + 1
        if key in self._key2deviceId:
            return self._key2deviceId[key]
        while device_id in self._clients:
            device_id += 1
        return device_id