From 65844d25fead82c5e0f84f088b05dc1438b60b6d Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Mon, 28 Nov 2022 19:59:55 -0600 Subject: [PATCH] cleanup pjlink variables and logic --- plugins/pjlink/main.js | 145 ++++++++++++++++++------------------ plugins/pjlink/template.ejs | 2 - 2 files changed, 72 insertions(+), 75 deletions(-) diff --git a/plugins/pjlink/main.js b/plugins/pjlink/main.js index ed235cc..1d1f4b4 100644 --- a/plugins/pjlink/main.js +++ b/plugins/pjlink/main.js @@ -19,59 +19,85 @@ exports.ready = function ready(device) { // Power status query // device.send("%1POWR ?\r"); }; + + +const PJLinkCmds = [ + '%1POWR=', + '%1INPT=', + '%1AVMT=', + '%1ERST=', + '%1LAMP=', + '%1NAME=', + '%1INF1=', + '%1INF2=', + '%2SNUM=', + '%2SVER=' +] + let password = false; -function processPJLink(device, str, that) { +function processPJLink(_device, str, that) { const arr = str.split('%'); arr.shift(); - const d = device; + const device = _device; - arr.forEach((s) => { - const split = s.split('='); - const key = split[0]; - const value = split[1]; + arr.forEach((response) => { + const parts = response.split('='); + const cmd = parts[0]; + const value = parts[1]; - if(key === '1POWR'){ - d.data.power = value; + switch (cmd) { + case '1POWR': + device.data.power = value; + break; - }else if(key === '1INPT'){ - d.data.input = value; - - }else if(key === '1AVMT'){ - d.data.avmute = value; - - }else if(key === '1ERST'){ - d.data.fanError = value[0]; - d.data.lampError = value[1]; - d.data.tempError = value[2]; - d.data.coverError = value[3]; - d.data.filterError = value[4]; - d.data.otherError = value[5]; - - }else if(key === '1LAMP'){ - d.data.lamp = value.split(' '); - - }else if(key === '1NAME'){ - d.data.name = value; - that.deviceInfoUpdate(d, 'defaultName', d.data.name); - - }else if(key === '1INF1'){ - d.data.info1 = value; - - }else if(key === '1INF2'){ - d.data.info2 = value; - - }else if(key === '2SNUM'){ - d.data.serial = value; - - }else if(key === '2SVER'){ - d.data.version = value; - + case '1INPT': + device.data.input = value; + break; + + case '1AVMT': + device.data.avmute = value; + break; + + case '1ERST': + device.data.fanError = value[0]; + device.data.lampError = value[1]; + device.data.tempError = value[2]; + device.data.coverError = value[3]; + device.data.filterError = value[4]; + device.data.otherError = value[5]; + break; + + case '1LAMP': + device.data.lamp = value.split(' '); + break; + + case '1NAME': + device.data.name = value; + that.deviceInfoUpdate(device, 'defaultName', device.data.name); + break; + + case '1INF1': + device.data.info1 = value; + break; + + case '1INF2': + device.data.info2 = value; + break; + + case '2SNUM': + device.data.serial = value; + break; + + case '2SVER': + device.data.version = value; + break; + + default: + break; } }); - - d.draw(); - + device.draw(); } exports.data = function data(device, message) { @@ -84,35 +110,8 @@ exports.data = function data(device, message) { `${password}%1POWR ?\r%1INPT ?\r%1AVMT ?\r%1ERST ?\r%1LAMP ?\r%1NAME ?\r%1INF1 ?\r%1INF2 ?\r%2SNUM ?\r%2SVER ?\r` ); } - if (msg.substring(0, 7) === '%1POWR=') { - processPJLink(device, msg, this); - } - if (msg.substring(0, 7) === '%1INPT=') { - processPJLink(device, msg, this); - } - if (msg.substring(0, 7) === '%1AVMT=') { - processPJLink(device, msg, this); - } - if (msg.substring(0, 7) === '%1ERST=') { - processPJLink(device, msg, this); - } - if (msg.substring(0, 7) === '%1LAMP=') { - processPJLink(device, msg, this); - } - if (msg.substring(0, 7) === '%1NAME=') { - processPJLink(device, msg, this); - } - if (msg.substring(0, 7) === '%1INF1=') { - processPJLink(device, msg, this); - } - if (msg.substring(0, 7) === '%1INF2=') { - processPJLink(device, msg, this); - } - if (msg.substring(0, 7) === '%2SNUM=') { - processPJLink(device, msg, this); - } - if (msg.substring(0, 7) === '%2SVER=') { - processPJLink(device, msg, this); + if(PJLinkCmds.includes(msg.substring(0,7))){ + processPJLink(device,msg,this) } }; diff --git a/plugins/pjlink/template.ejs b/plugins/pjlink/template.ejs index ae4bde7..3df8cd2 100644 --- a/plugins/pjlink/template.ejs +++ b/plugins/pjlink/template.ejs @@ -2,7 +2,6 @@

<%= listName %>

- @@ -73,7 +72,6 @@ <% } %> <% } %> -
Power
Name
<%= data.name %>