diff --git a/node-red-contrib-xiaomi-ht/xiaomi-ht.html b/node-red-contrib-xiaomi-ht/xiaomi-ht.html
index 9187d11..8ec2204 100644
--- a/node-red-contrib-xiaomi-ht/xiaomi-ht.html
+++ b/node-red-contrib-xiaomi-ht/xiaomi-ht.html
@@ -23,10 +23,37 @@
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);
+ if(node.sid) {
+ $('#node-input-sid').val(node.sid);
+ }
+
+ function changeGateway(model) {
+ var configNodeID = $('#node-input-gateway').val();
+ if (configNodeID) {
+ var configNode = RED.nodes.node(configNodeID);
+ if(configNode) {
+ $('#node-input-sid').empty();
+ for (key in configNode.deviceList) {
+ var device = configNode.deviceList[key];
+ if (device.model === model) {
+ $('#node-input-sid').append('');
+ }
+ }
+ if(node.sid) {
+ $('#node-input-sid option[value="' + node.sid + '"]').prop('selected', true);
+ }
+ }
+ }
+ }
+
+ $("#node-input-sid").change(function () {
+ if(!this.name) {
+ $("#node-input-name").val($('#node-input-sid option:selected').text());
+ }
+ });
+ $("#node-input-gateway").change(function () {
+ changeGateway("sensor_ht");
+ });
$("#node-input-output").change(function () {
if ($(this).val() == "2") {
@@ -38,18 +65,6 @@
$(".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];
- if (device.model === "sensor_ht") {
- $('#node-input-sid').append('');
- }
- }
- $('#node-input-sid').val(node.sid);
},
oneditsave: function() {
var node = this;
@@ -88,7 +103,7 @@
-
+
diff --git a/node-red-contrib-xiaomi-magnet/xiaomi-magnet.html b/node-red-contrib-xiaomi-magnet/xiaomi-magnet.html
index 4c46b8e..9cf92ed 100644
--- a/node-red-contrib-xiaomi-magnet/xiaomi-magnet.html
+++ b/node-red-contrib-xiaomi-magnet/xiaomi-magnet.html
@@ -21,10 +21,37 @@
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);
+ if(node.sid) {
+ $('#node-input-sid').val(node.sid);
+ }
+
+ function changeGateway(model) {
+ var configNodeID = $('#node-input-gateway').val();
+ if (configNodeID) {
+ var configNode = RED.nodes.node(configNodeID);
+ if(configNode) {
+ $('#node-input-sid').empty();
+ for (key in configNode.deviceList) {
+ var device = configNode.deviceList[key];
+ if (device.model === model) {
+ $('#node-input-sid').append('');
+ }
+ }
+ if(node.sid) {
+ $('#node-input-sid option[value="' + node.sid + '"]').prop('selected', true);
+ }
+ }
+ }
+ }
+
+ $("#node-input-sid").change(function () {
+ if(!this.name) {
+ $("#node-input-name").val($('#node-input-sid option:selected').text());
+ }
+ });
+ $("#node-input-gateway").change(function () {
+ changeGateway("magnet");
+ });
$("#node-input-output").change(function () {
if ($(this).val() == "2") {
@@ -33,18 +60,6 @@
$(".node-input-msg").hide();
}
});
-
- $("#node-input-gateway").change(function () {
-
- });
-
- for (key in configNode.deviceList) {
- var device = configNode.deviceList[key];
- if (device.model === "magnet") {
- $('#node-input-sid').append('');
- }
- }
- $('#node-input-sid').val(node.sid);
},
oneditsave: function() {
var node = this;
diff --git a/node-red-contrib-xiaomi-motion/xiaomi-motion.html b/node-red-contrib-xiaomi-motion/xiaomi-motion.html
index 3d29e69..21d9602 100644
--- a/node-red-contrib-xiaomi-motion/xiaomi-motion.html
+++ b/node-red-contrib-xiaomi-motion/xiaomi-motion.html
@@ -21,10 +21,37 @@
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);
+ if(node.sid) {
+ $('#node-input-sid').val(node.sid);
+ }
+
+ function changeGateway(model) {
+ var configNodeID = $('#node-input-gateway').val();
+ if (configNodeID) {
+ var configNode = RED.nodes.node(configNodeID);
+ if(configNode) {
+ $('#node-input-sid').empty();
+ for (key in configNode.deviceList) {
+ var device = configNode.deviceList[key];
+ if (device.model === model) {
+ $('#node-input-sid').append('');
+ }
+ }
+ if(node.sid) {
+ $('#node-input-sid option[value="' + node.sid + '"]').prop('selected', true);
+ }
+ }
+ }
+ }
+
+ $("#node-input-sid").change(function () {
+ if(!this.name) {
+ $("#node-input-name").val($('#node-input-sid option:selected').text());
+ }
+ });
+ $("#node-input-gateway").change(function () {
+ changeGateway("magnet");
+ });
$("#node-input-output").change(function () {
if ($(this).val() == "2") {
@@ -33,18 +60,6 @@
$(".node-input-msg").hide();
}
});
-
- $("#node-input-gateway").change(function () {
-
- });
-
- for (key in configNode.deviceList) {
- var device = configNode.deviceList[key];
- if (device.model === "motion") {
- $('#node-input-sid').append('');
- }
- }
- $('#node-input-sid').val(node.sid);
},
oneditsave: function() {
var node = this;
diff --git a/node-red-contrib-xiaomi-switch/xiaomi-switch.html b/node-red-contrib-xiaomi-switch/xiaomi-switch.html
index 67ac876..f701634 100644
--- a/node-red-contrib-xiaomi-switch/xiaomi-switch.html
+++ b/node-red-contrib-xiaomi-switch/xiaomi-switch.html
@@ -21,10 +21,37 @@
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);
+ if(node.sid) {
+ $('#node-input-sid').val(node.sid);
+ }
+
+ function changeGateway(model) {
+ var configNodeID = $('#node-input-gateway').val();
+ if (configNodeID) {
+ var configNode = RED.nodes.node(configNodeID);
+ if(configNode) {
+ $('#node-input-sid').empty();
+ for (key in configNode.deviceList) {
+ var device = configNode.deviceList[key];
+ if (device.model === model) {
+ $('#node-input-sid').append('');
+ }
+ }
+ if(node.sid) {
+ $('#node-input-sid option[value="' + node.sid + '"]').prop('selected', true);
+ }
+ }
+ }
+ }
+
+ $("#node-input-sid").change(function () {
+ if(!this.name) {
+ $("#node-input-name").val($('#node-input-sid option:selected').text());
+ }
+ });
+ $("#node-input-gateway").change(function () {
+ changeGateway("magnet");
+ });
$("#node-input-output").change(function () {
if ($(this).val() == "2") {
@@ -36,18 +63,6 @@
$(".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];
- if (device.model === "switch") {
- $('#node-input-sid').append('');
- }
- }
- $('#node-input-sid').val(node.sid);
},
oneditsave: function() {
var node = this;