UNPKG

node-red-contrib-susi

Version:
140 lines (121 loc) 5.16 kB
<!-- Copyright 2014, 2015 ADVANTECH Corp. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <!-- Define the edit dialog. --> <script type="text/x-red" data-template-name="SUSI-HardwareMonitor"> <div class="form-row"> <label for="node-input-topic"><i class="fa fa-tasks"></i> Topic</label> <input type="text" id="node-input-topic" placeholder="Topic"> </div> <br/> <div class="form-row"> <label for="node-input-functiontype"><i class="fa fa-list"></i> Type</label> <select id="node-input-functiontype" onchange="HardwareMonitorChangeIndex()"></select> </div> <br/> <div class="form-row"> <label for="node-input-index"><i class="fa fa-list"></i> Index</label> <select id="node-input-index"> </select> </div> <br/> <!-- Node name --> <div class="form-row"> <label for="node-input-name"><i class="icon-tag"></i> Name</label> <input type="text" id="node-input-name" placeholder="Name"> </div> </script> <!-- Next, some simple help text is provided for the node. --> <script type="text/x-red" data-help-name="SUSI-HardwareMonitor"> <p>Node to retrieve the status of a ADVANTECH platform by SUSI, either at startup, or at a predefined period, determined by an input message</p> <p>Outputs a <b>msg</b> containing <b>msg.topic</b> which defaults to the sensor name, and <b>msg.payload</b> containing the reading.</p> </script> <script type="text/javascript"> RED.nodes.registerType('SUSI-HardwareMonitor', { category: 'ADVANTECH', // the palette category defaults: { // defines the editable properties of the node name: {value: ""}, topic: {value: "SUSI HardwareMonitor"}, dht: {value: 22}, functiontype: {value: 0}, index: {value: 0} }, inputs: 1, // set the number of inputs - only 0 or 1 outputs: 1, // set the number of outputs - 0 to n color: "#C0DEED", icon: "dht.png", // saved in icons/myicon.png paletteLabel: "HardwareMonitor", label: function() { // sets the default label contents return this.name||this.topic||"SUSI-HardwareMonitor"; }, labelStyle: function() { // sets the class to apply to the label return this.name ? "node_label_italic": ""; }, oneditprepare: ws_oneditprepare }); function HardwareMonitorChangeIndex(){ var tp = $("#node-input-functiontype").val(); var list = ""; if(tp == 0) { list = temperaturelist; } else if(tp == 1) { list = fanspeedlist; } else if(tp == 2) { list = voltagelist; }else if(tp == 3) { list = currentlist; } $("#node-input-index").html(list); }; var indextemp, functiontypetemp; function ws_oneditprepare() { functiontypetemp = this.functiontype; indextemp = this.index; $.getJSON('SUSI-HardwareMonitor',function(data) { temperaturelist = ""; for (var i=0; i<10; i++) { if(data[0][i].indexOf("failed") == -1 && data[0][i] != "") temperaturelist = temperaturelist + "<option value=" + i + ">" + data[0][i] + "</option>"; } fanspeedlist = ""; for (var i=0; i<10; i++) { if(data[1][i].indexOf("failed") == -1 && data[1][i] != "") fanspeedlist = fanspeedlist + "<option value=" + i + ">" + data[1][i] + "</option>"; } voltagelist = ""; for (var i=0; i<23; i++) { if(data[2][i].indexOf("failed") == -1 && data[2][i] != "") voltagelist = voltagelist + "<option value=" + i + ">" + data[2][i] + "</option>"; } currentlist = ""; for (var i=0; i<3; i++) { if(data[3][i].indexOf("failed") == -1 && data[3][i] != "") currentlist = currentlist + "<option value=" + i + ">" + data[3][i] + "</option>"; } functiontypelist = ""; if(temperaturelist != "") functiontypelist = functiontypelist + "<option value='0'>Temperature</option>"; if(fanspeedlist != "") functiontypelist = functiontypelist + "<option value='1'>Fan Speed</option>"; if(voltagelist != "") functiontypelist = functiontypelist + "<option value='2'>Voltage</option>"; if(currentlist != "") functiontypelist = functiontypelist + "<option value='3'>Current</option>"; $("#node-input-functiontype").html(functiontypelist); $("#node-input-functiontype").val(functiontypetemp); HardwareMonitorChangeIndex(); $("#node-input-index").val(indextemp); }); }; </script>