From 4645f0b803e6c50fcdbd79cdc9937412959c797d Mon Sep 17 00:00:00 2001 From: Harald Rietman Date: Fri, 30 Jun 2017 19:14:32 +0200 Subject: [PATCH] Working config node and xiaomi-ht node, added package.json --- .gitignore | 3 + .../xiaomi-gateway.html | 84 +++++++++++++++---- .../xiaomi-gateway.js | 5 +- node-red-contrib-xiaomi-ht/xiaomi-ht.html | 32 ++++++- node-red-contrib-xiaomi-ht/xiaomi-ht.js | 57 +------------ package.json | 20 +++++ 6 files changed, 124 insertions(+), 77 deletions(-) create mode 100644 .gitignore create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..472b029 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# Created by .ignore support plugin (hsz.mobi) + +*.iml diff --git a/node-red-contrib-xiaomi-gateway/xiaomi-gateway.html b/node-red-contrib-xiaomi-gateway/xiaomi-gateway.html index 27bc130..0ea9b93 100644 --- a/node-red-contrib-xiaomi-gateway/xiaomi-gateway.html +++ b/node-red-contrib-xiaomi-gateway/xiaomi-gateway.html @@ -3,12 +3,75 @@ category: 'config', defaults: { name: {value: ""}, - group: {value: "224.0.0.50", required: true}, - port: {value: 9898, required: true, validate:RED.validators.number()}, - udpv: {value: "udp4"} + deviceList: {value:[{ sid:"a", desc:"b", model:"plug"}]} }, label: function () { return this.name || "xiaomi-gateway"; + }, + oneditprepare: function() { + var node = this; + + console.log("config window openend: " + node.deviceList); + + $("#node-config-input-devices").css('min-height','250px').css('min-width','450px').editableList({ + addItem: function(container, i, device) { + if (!device.hasOwnProperty('model')) { + device.model = 'sensor_ht'; + } + var row = $('
').appendTo(container); + + $('
- -
- - -
-
- - - using - +
+
    diff --git a/node-red-contrib-xiaomi-gateway/xiaomi-gateway.js b/node-red-contrib-xiaomi-gateway/xiaomi-gateway.js index cf5695f..e6838e7 100644 --- a/node-red-contrib-xiaomi-gateway/xiaomi-gateway.js +++ b/node-red-contrib-xiaomi-gateway/xiaomi-gateway.js @@ -3,12 +3,9 @@ module.exports = function(RED) { function RemoteServerNode(n) { RED.nodes.createNode(this, n); this.name = n.name; - this.group = n.group; - this.port = n.port; - this.udpv = n.udpv; + this.deviceList = n.deviceList || []; var node = this; - } RED.nodes.registerType("xiaomi-gateway", RemoteServerNode); diff --git a/node-red-contrib-xiaomi-ht/xiaomi-ht.html b/node-red-contrib-xiaomi-ht/xiaomi-ht.html index 996afd4..8f0feed 100644 --- a/node-red-contrib-xiaomi-ht/xiaomi-ht.html +++ b/node-red-contrib-xiaomi-ht/xiaomi-ht.html @@ -5,12 +5,12 @@ defaults: { gateway: {value:"", type:"xiaomi-gateway"}, name: {value: ""}, - sid: {value: "", required: true, validate: RED.validators.regex(/^[a-f0-9]{14}$/)}, + sid: {value: "", required: true}, temperature: {value: "{{temperature}}"}, humidity: {value: "{{humidity}}"}, output: {value: "0"} }, - inputs: 0, + inputs: 1, outputs: 2, outputLabels: ["Temperature","Humidity"], icon: "thermometer-icon.png", @@ -18,6 +18,13 @@ return this.name || "xiaomi-ht"; }, oneditprepare: function() { + var node = this; + + // Get the config node id from the select box: + var configNodeID = $('#node-input-gateway').val(); + // Get the config node using the ID: + var configNode = RED.nodes.node(configNodeID); + $("#node-input-output").change(function () { if ($(this).val() == "2") { $(".node-input-msg").show(); @@ -29,6 +36,19 @@ $(".node-input-msg").hide(); $("#node-input-output").val(node.output); + $("#node-input-gateway").change(function () { + + }); + + for (key in configNode.deviceList) { + var device = configNode.deviceList[key]; + $('#node-input-sid').append(''); + } + $('#node-input-sid').val(node.sid); + }, + oneditsave: function() { + var node = this; + node.sid = $("#node-input-sid").val(); } }); @@ -43,9 +63,13 @@
    - - + +
    + + + +