marshalHomie(value, datatype) {
        if (value === null || value === undefined) {
            return null;
        }

        if (value instanceof Buffer) {
            if (datatype !== DataType.STRING) {
                throw new Error("Outbound Buffer is only allowed for data of type STRING");
            } else {
                return value;
            }
        }

        switch (datatype) {
            case DataType.STRING:
            case DataType.ENUM:
            case DataType.COLOR:
                if (typeof value === "object") {
                    value = JSON.stringify(value);
                }

                if (typeof value !== "string") {
                    throw new Error("Value must be a string or a buffer!");
                }

                if (datatype === DataType.ENUM && datatype === this.dataType && this.format.split(",").indexOf(value) < 0) {
                    throw new Error("Value '" + value + "' is invalid for enum with format [" + this.format + "]!");
                }

                return value;
            case DataType.INTEGER:
                return Math.round(value).toString();
            case DataType.FLOAT:
                return value.toString();
            case DataType.DATETIME:
                if (value.prototype.toISOString === undefined) {
                    throw new Error("Date value must be a Date object!");
                }

                return value.prototype.toISOString();
            case DataType.DURATION:
                return iso8601.numberToDuration(value);
            case DataType.BOOLEAN:
                return value ? "true" : "false";
            default:
                return JSON.stringify(value);
        }
    }
Converts a JS value to a Homie-compatible value, based on the provided data type

@protected
@param {*} value
@param {string} datatype
@return {string|Buffer|null}