fix(all): check onlyModels server side

This commit is contained in:
Pierre CLEMENT
2018-01-08 21:02:40 +01:00
parent 234f91c2cf
commit c85e131bc1
3 changed files with 11 additions and 13 deletions

View File

@@ -1,12 +1,4 @@
<script type="text/javascript">
function getOnlyModelsValue(input) {
var cleanOnlyModels = [];
input.forEach(function(value) {
cleanOnlyModels = cleanOnlyModels.concat(value.split(','));
});
return cleanOnlyModels;
}
RED.nodes.registerType('xiaomi-all', {
category: 'xiaomi',
color: '#3FADB5',
@@ -32,7 +24,7 @@
if (configNodeID) {
var configNode = RED.nodes.node(configNodeID);
if(configNode) {
onlyModels = getOnlyModelsValue(onlyModels || $('#node-input-onlyModels').val() || []);
onlyModels = onlyModels || $('#node-input-onlyModels').val() || [];
excludedSids = excludedSids || $('#node-input-excludedSids').val() || [];
$('#node-input-excludedSids').empty();
for (key in configNode.deviceList) {
@@ -61,7 +53,6 @@
if(!$('#node-input-excludedSids').val()) {
this.excludedSids = [];
}
this.onlyModels = getOnlyModelsValue(this.onlyModels);
}
});
</script>

View File

@@ -1,15 +1,22 @@
module.exports = (RED) => {
function getOnlyModelsValue(input) {
var cleanOnlyModels = [];
input.forEach((value) => {
cleanOnlyModels = cleanOnlyModels.concat(value.split(','));
});
return cleanOnlyModels;
}
function XiaomiAllNode(config) {
RED.nodes.createNode(this, config);
this.gateway = RED.nodes.getNode(config.gateway);
this.onlyModels = config.onlyModels;
this.onlyModels = getOnlyModelsValue(config.onlyModels || []);
this.excludedSids = config.excludedSids;
console.log(this.onlyModels);
this.isDeviceValid = (device) => {
console.log(device.sid, device.model, this.onlyModels, this.excludeSids);
if((!this.onlyModels || this.onlyModels.length == 0) && (!this.excludedSids || this.excludedSids.length == 0)) {
return true;
}

View File

@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-mi-devices",
"version": "1.0.5",
"version": "1.0.6",
"description": "A set of nodes to control some of the popular Xiaomi sensors which are connected to the Xiaomi Gateway, and the Gateway itself.",
"repository": {
"type": "git",