SOURCE

function getCheckSum(payload) {
    var checkSum = 0;
    for (i = 0; i < payload.length - 1; i++) {
        checkSum = checkSum + parseInt(payload[i]);
    }
    return checkSum & 0xff;
}
var cmd = "";
console.log(command);
var checkSum = 0;
if (command.command == "shadow" && command.method == "set") {
    if ('Volume' in command.d) {
        var result = {}
        var cmdArr = [0xFF, 0x55, 0x04, 0x88, 0x01, 0x01, command.d.Volume, 0]
        checkSum = getCheckSum(cmdArr);
        cmdArr[cmdArr.length - 1] = checkSum;
        result.commandArray = [cmdArr, [0xFF, 0x55, 0x04, 0x44, 0x01, 0x01, 0x00, 0x9E]];
        result.commandIntervalArray = [5, 20];
        return result;
    } else if ('Brightness' in command.d) {
        var cmdArr = [0xFF, 0x55, 0x04, 0x30, 0x01, 0x01, command.d.Brightness, checkSum]
        checkSum = getCheckSum(cmdArr);
        cmdArr[cmdArr.length - 1] = checkSum;
        var result = {}
        result.commandArray = [cmdArr, [0xFF, 0x55, 0x04, 0x40, 0x01, 0x01, 0x00, 0x9A]];
        result.commandIntervalArray = [5, 20];
        return result;
    } else if ('InputSource' in command.d) {
        var value = parseInt(command.d.InputSource)
        var cmdArr = [0xFF, 0x55, 0x04, 0x82, 0x01, 0x01, value, checkSum]
        checkSum = getCheckSum(cmdArr);
        cmdArr[cmdArr.length - 1] = checkSum;
        var result = {}
        result.commandArray = [cmdArr, [0xFF, 0x55, 0x04, 0x42, 0x01, 0x01, 0x00, 0x9C]];
        result.commandIntervalArray = [5, 20];
        return result;
    } else if ('Backlight' in command.d) {
        var value = parseInt(command.d.Backlight)
        var cmdArr = [0xFF, 0x55, 0x04, 0x66, 0x01, 0x01, value, checkSum]
        checkSum = getCheckSum(cmdArr);
        cmdArr[cmdArr.length - 1] = checkSum;
        var result = {}
        result.commandArray = [cmdArr, [0xFF, 0x55, 0x04, 0x56, 0x01, 0x01, 0x00, 0xB0]];
        result.commandIntervalArray = [5, 50];
        return result;
    } else if ('Contrast' in command.d) {
        var value = parseInt(command.d.Contrast)
        var cmdArr = [0xFF, 0x55, 0x04, 0x81, 0x01, 0x01, value, checkSum]
        checkSum = getCheckSum(cmdArr);
        cmdArr[cmdArr.length - 1] = checkSum;
        var result = {}
        result.commandArray = [cmdArr, [0xFF, 0x55, 0x04, 0x41, 0x01, 0x01, 0x00, 0x9B]];
        result.commandIntervalArray = [5, 50];
        return result;
    } else if ('Sharpness' in command.d) {
        var value = parseInt(command.d.Sharpness)
        var cmdArr = [0xFF, 0x55, 0x04, 0x61, 0x01, 0x01, value, checkSum]
        checkSum = getCheckSum(cmdArr);
        cmdArr[cmdArr.length - 1] = checkSum;
        var result = {}
        result.commandArray = [cmdArr, [0xFF, 0x55, 0x04, 0x51, 0x01, 0x01, 0x00, 0xAB]];
        result.commandIntervalArray = [5, 50];
        return result;
    } else if ('Gama' in command.d) {
        var value = parseInt(command.d.Gama)
        var cmdArr = [0xFF, 0x55, 0x04, 0x62, 0x01, 0x01, value, checkSum]
        checkSum = getCheckSum(cmdArr);
        cmdArr[cmdArr.length - 1] = checkSum;
        var result = {}
        result.commandArray = [cmdArr, [0xFF, 0x55, 0x04, 0x52, 0x01, 0x01, 0x00, 0xAC]];
        result.commandIntervalArray = [5, 50];
        return result;
    } else if ('AudioSwitchStatus' in command.d) {
        var value = parseInt(command.d.AudioSwitchStatus)
        var cmdArr = [0xFF, 0x55, 0x04, 0x87, 0x01, 0x01, value, checkSum]
        checkSum = getCheckSum(cmdArr);
        cmdArr[cmdArr.length - 1] = checkSum;
        var result = {}
        result.commandArray = [cmdArr, [0xFF, 0x55, 0x04, 0x43, 0x01, 0x01, 0x00, 0x9D]];
        result.commandIntervalArray = [5, 50];
        return result;
    } else if ('AutoReportSwitchStatus' in command.d) {
        var value = parseInt(command.d.AutoReportSwitchStatus)
        var cmdArr = [0xFF, 0x55, 0x04, 0xAC, 0x00, value, 0x00, checkSum]
        checkSum = getCheckSum(cmdArr);
        cmdArr[cmdArr.length - 1] = checkSum;
        var result = {}
        result.commandArray = [cmdArr, [0xFF, 0x55, 0x04, 0xab, 0x00, 0x00, 0x00, 0x03]];
        result.commandIntervalArray = [5, 50];
        return result;
    }
} else if (command.command == "PowerOn") {
    var result = {}
    result.commandArray = [[0xFF, 0x55, 0x04, 0x84, 0x01, 0x01, 0x00, 0xDE], [0xFF, 0x55, 0x04, 0x39, 0x00, 0x00, 0x00, 0x91]];
    result.commandIntervalArray = [5, 100];
    return result;
} else if (command.command == "PowerOff") {
    return [0xFF, 0x55, 0x04, 0x83, 0x01, 0x01, 0x00, 0xDD];
} else if (command.command == "Reboot") {
    var result = {}
    result.commandArray = [[0xFF, 0x55, 0x04, 0x83, 0x01, 0x01, 0x00, 0xDD], [0xFF, 0x55, 0x04, 0x39, 0x00, 0x00, 0x00, 0x91], [0xFF, 0x55, 0x04, 0x84, 0x01, 0x01, 0x00, 0xDE], [0xFF, 0x55, 0x04, 0x39, 0x00, 0x00, 0x00, 0x91]];
    result.commandIntervalArray = [5, 200, 2000, 200];
    return result;
} else if (command.command == "AutomaticDimming") {
    var mode = command.d.mode;
    var switchCmd = [];
    if (mode == "0") {
        switchCmd = [0xFF, 0x55, 0x04, 0x21, 0x01, 0x01, 0x00, 0x7B];
    } else {
        switchCmd = [0xFF, 0x55, 0x04, 0x21, 0x01, 0x01, 0x01, 0x7C];
    }
    var v1l = command.d.ambientLight1 % 256;
    var v1h = parseInt(command.d.ambientLight1 / 256);
    var bl1 = command.d.backlight1;

    var v2l = command.d.ambientLight2 % 256;
    var v2h = parseInt(command.d.ambientLight2 / 256);
    var bl2 = command.d.backlight2;

    var v3l = command.d.ambientLight3 % 256;
    var v3h = parseInt(command.d.ambientLight3 / 256);
    var bl3 = command.d.backlight3;

    var v4l = command.d.ambientLight4 % 256;
    var v4h = parseInt(command.d.ambientLight4 / 256);
    var bl4 = command.d.backlight4;

    var v5l = command.d.ambientLight5 % 256;
    var v5h = parseInt(command.d.ambientLight5 / 256);
    var bl5 = command.d.backlight5;

    var setCmd = [0xFF, 0x55, 0x0f, 0x3B, v1l, v1h, bl1, v2l, v2h, bl2, v3l, v3h, bl3, v4l, v4h, bl4, v5l, v5h, bl5, checkSum];
    checkSum = getCheckSum(setCmd);
    setCmd[setCmd.length - 1] = checkSum;
    var result = {};
    result.commandArray = [switchCmd, setCmd];
    result.commandIntervalArray = [5, 20];
    return result;
} else if (command.command == "RGB") {
    var redVal = command.d.red;
    var redCheckSum = 0;
    var redCmd = [0xFF, 0x55, 0x04, 0x63, 0x01, 0x01, redVal, redCheckSum];
    redCheckSum = getCheckSum(redCmd);
    redCmd[redCmd.length - 1] = redCheckSum;

    var greenVal = command.d.green;
    var greenCheckSum = 0;
    var greenCmd = [0xFF, 0x55, 0x04, 0x64, 0x01, 0x01, greenVal, greenCheckSum];
    greenCheckSum = getCheckSum(greenCmd);
    greenCmd[greenCmd.length - 1] = greenCheckSum;

    var blueVal = command.d.blue;
    var blueCheckSum = 0;
    var blueCmd = [0xFF, 0x55, 0x04, 0x65, 0x01, 0x01, blueVal, blueCheckSum];
    blueCheckSum = getCheckSum(blueCmd);
    blueCmd[blueCmd.length - 1] = blueCheckSum;

    var result = {}
    result.commandArray = [redCmd, greenCmd, blueCmd];
    result.commandIntervalArray = [10, 10, 10];
    return result;
} else if (command.command == "TimeAutomaticDimming") {
    var h1 = command.d.h1;
    var m1 = command.d.m1;
    var bl1 = command.d.backlight1;

    var h2 = command.d.h2;
    var m2 = command.d.m2;
    var bl2 = command.d.backlight2;

    var h3 = command.d.h3;
    var m3 = command.d.m3;
    var bl3 = command.d.backlight3;

    var h4 = command.d.h4;
    var m4 = command.d.m4;
    var bl4 = command.d.backlight4;

    var h5 = command.d.h5;
    var m5 = command.d.m5;
    var bl5 = command.d.backlight5;

    var setCmd = [0xFF, 0x55, 0x0f, 0x23, h1, m1, bl1, h2, m2, bl2, h3, m3, bl3, h4, m4, bl4, h5, m5, bl5, checkSum];
    checkSum = getCheckSum(setCmd);
    setCmd[setCmd.length - 1] = checkSum;

    var result = {};
    result.commandArray = [setCmd];
    result.commandIntervalArray = [5];
    return result;
} else if (command.command == "SensorSetting") {
    var sensorType = parseInt(command.d.sensorType);
    var switchStatus = parseInt(command.d.switchStatus);
    var reportCycle = command.d.reportCycle;

    var periodLow = reportCycle & 0x00ff
    var periodHigh = (reportCycle & 0xff00) >> 8
    var setCmd = [0xFF, 0x55, 0x05, 0xa9, sensorType, switchStatus, periodLow, periodHigh, 0x00];
    checkSum = getCheckSum(setCmd);
    setCmd[setCmd.length - 1] = checkSum;

    var readCmd=[0xFF,0x55,0x04,0xa8,sensorType,0x00,0x00,0x00];
    var readCmdcheckSum = getCheckSum(readCmd);
    readCmd[readCmd.length - 1] = readCmdcheckSum;

    var result = {};
    result.commandArray = [setCmd,readCmd];
    result.commandIntervalArray = [5,50];
    return result;
} else {
    return [0xFF, 0x55, 0x04, 0xab, 0x00, 0x00, 0x03];
}
console 命令行工具 X clear

                    
>
console