UNPKG

node-red-contrib-smartthings

Version:
108 lines (93 loc) 3.74 kB
<script type="text/javascript"> RED.nodes.registerType('smartthings-node-scene',{ category: 'Smartthings', defaults: { conf: {value:"", type:"smartthings-config"}, name: {value: ""}, scene: {value: "", required:true} }, paletteLabel: "Scene", icon: 'scene.png', outputs: 0, inputs: 1, label: function() { return this.name || "Execute Scene"; }, oneditprepare: function(){ var node = this; var getScenes = function(conf){ const confObj = RED.nodes.node(conf); $('#node-input-scene').find('option').remove().end(); $('<option/>',{ value: "", text: "Loading..." }).appendTo('#node-input-scene'); $.getJSON('smartthings/'+confObj.token+'/scenes', function(data){ console.log("getScenes"); console.log(data); $('#node-input-scene').find('option').remove().end(); $('<option/>',{ value: "", text: "" }).appendTo('#node-input-scene'); for (d in data) { $('<option/>',{ value: data[d].sceneId, text: data[d].sceneName }).appendTo('#node-input-scene'); } if (node.scene) { $('#node-input-scene').val(node.scene); } }); }; if(node.conf){ getScenes(node.conf); } $('#node-input-scene').change(function(){ var device = $('#node-input-scene option:selected'); if(device.get(0) && device.val() && device.val() !== ""){ $('#node-input-name').val(device.text()); } }); $('#node-input-conf').change(function(){ var conf = $('#node-input-conf').val(); console.log("conf changed: ", conf); if (conf != '_ADD_') { getScenes(conf); } else { $('#node-input-scene').find('option').remove().end(); $('#node-input-scene').val(""); } }); } }); </script> <script type="text/x-red" data-template-name="smartthings-node-scene"> <div class="form-row"> <label for="node-input-conf"><i class="fa fa-tag"></i> Account</label> <input type="text" id="node-input-conf"> </div> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-input-name" placeholder="Name"> </div> <div class="form-row"> <label for="node-input-scene"><i class="fa fa-tag"></i> Scene</label> <select type="text" id="node-input-scene" style="display: inline-block; width: 70%;"> <option value="empty"></option> </select> </div> </script> <script type="text/x-red" data-help-name="smartthings-node-scene"> <p>This Node represents a scene to be executes.</p> <h3>Input</h3> <dl class="message-properties"> <dt class="optional">topic <span class="property-type">string</span></dt> <dd><code>scene</code> execute the selected scene</dd> </dl> <h3>Details</h3> <p> This node represents a scene to be executed. </p> </script>