feat(all): add all devices node

This commit is contained in:
Pierre CLEMENT
2018-01-01 03:54:28 +01:00
parent 7742e99f75
commit 3ebdbf9100
4 changed files with 66 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@@ -0,0 +1,43 @@
<script type="text/javascript">
RED.nodes.registerType('xiaomi-all', {
category: 'xiaomi',
color: '#3FADB5',
defaults: {
gateway: {value:"", type:"xiaomi-configurator"},
name: {value: ""}
},
inputs: 1,
outputs: 1,
outputLabels: ["All devices"],
paletteLabel: "all",
icon: "light-icon.png",
label: function () {
return this.name || "xiaomi-all";
}
});
</script>
<script type="text/x-red" data-template-name="xiaomi-all">
<div class="form-row">
<label for="node-input-gateway"><i class="icon-tag"></i> Gateway</label>
<input type="text" id="node-input-gateway" placeholder="xiaomi gateway">
</div>
<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>
<script type="text/x-red" data-help-name="xiaomi-all">
<p>All devices registred in the gateway.</p>
<h3>Outputs</h3>
<ol class="node-ports">
<li>Devices output
<dl class="message-properties">
<dt>payload <span class="property-type">array</span></dt>
<dd>Array of devices.</dd>
</dl>
</li>
</ol>
</script>

View File

@@ -0,0 +1,22 @@
module.exports = function(RED) {
"use strict";
var mustache = require("mustache");
var miDevicesUtils = require('../utils');
function XiaomiAllNode(config) {
RED.nodes.createNode(this, config);
this.gateway = RED.nodes.getNode(config.gateway);
var node = this;
if (this.gateway) {
node.on('input', function(msg) {
msg.payload = node.gateway.deviceList;
node.send(msg);
});
}
}
RED.nodes.registerType("xiaomi-all", XiaomiAllNode);
}

View File

@@ -16,6 +16,7 @@
"xiaomi-switch": "node-red-contrib-xiaomi-switch/xiaomi-switch.js",
"xiaomi-socket": "node-red-contrib-xiaomi-socket/xiaomi-socket.js",
"xiaomi-socket-wifi": "node-red-contrib-xiaomi-socket-wifi/xiaomi-socket-wifi.js",
"xiaomi-all": "node-red-contrib-xiaomi-all/xiaomi-all.js",
"xiaomi-configurator": "node-red-contrib-xiaomi-configurator/xiaomi-configurator.js",
"xiaomi-gateway": "node-red-contrib-xiaomi-gateway/xiaomi-gateway.js",
"xiaomi-actions": "node-red-contrib-xiaomi-actions/xiaomi-actions.js"