feat(gateway): add a node to access a gateway
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 10 KiB |
BIN
node-red-contrib-xiaomi-all/icons/xiaomi-all-icon.png
Normal file
BIN
node-red-contrib-xiaomi-all/icons/xiaomi-all-icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 699 B |
@@ -10,7 +10,7 @@
|
||||
outputs: 1,
|
||||
outputLabels: ["All devices"],
|
||||
paletteLabel: "all",
|
||||
icon: "light-icon.png",
|
||||
icon: "xiaomi-all-icon.png",
|
||||
label: function () {
|
||||
return this.name || "xiaomi-all";
|
||||
}
|
||||
|
||||
BIN
node-red-contrib-xiaomi-gateway/icons/gateway-icon.png
Normal file
BIN
node-red-contrib-xiaomi-gateway/icons/gateway-icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 653 B |
@@ -1,3 +1,48 @@
|
||||
<!-- The Input Node -->
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('xiaomi-gateway', {
|
||||
category: 'xiaomi',
|
||||
color: '#3FADB5',
|
||||
defaults: {
|
||||
gateway: {value:"", type:"xiaomi-configurator"},
|
||||
name: {value: ""}
|
||||
},
|
||||
inputs: 1,
|
||||
outputs: 1,
|
||||
outputLabels: ["Gateway"],
|
||||
paletteLabel: "gateway",
|
||||
icon: "gateway-icon.png",
|
||||
label: function () {
|
||||
return this.name || "xiaomi-gateway";
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-template-name="xiaomi-gateway">
|
||||
<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-gateway">
|
||||
<p>The gateway itself.</p>
|
||||
|
||||
<h3>Outputs</h3>
|
||||
<ol class="node-ports">
|
||||
<li>Devices output
|
||||
<dl class="message-properties">
|
||||
<dt>gateway <span class="property-type">xiaomi-configurator</span></dt>
|
||||
<dd>The gateway.</dd>
|
||||
</dl>
|
||||
</li>
|
||||
</ol>
|
||||
</script>
|
||||
|
||||
<!-- The Input Node -->
|
||||
<script type="text/x-red" data-template-name="xiaomi-gateway in">
|
||||
<div class="form-row">
|
||||
@@ -22,7 +67,7 @@
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('xiaomi-gateway in',{
|
||||
category: 'xiaomi in-out',
|
||||
category: 'xiaomi in out',
|
||||
color: '#087F8A',
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
@@ -83,7 +128,7 @@
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('xiaomi-gateway out',{
|
||||
category: 'xiaomi in-out',
|
||||
category: 'xiaomi in out',
|
||||
color: '#087F8A',
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
|
||||
@@ -1,24 +1,23 @@
|
||||
/**
|
||||
* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
module.exports = function(RED) {
|
||||
"use strict";
|
||||
var dgram = require('dgram');
|
||||
var udpInputPortsInUse = {};
|
||||
|
||||
function XiaomiGatewayNode(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.gateway = node.gateway;
|
||||
node.send(msg);
|
||||
});
|
||||
}
|
||||
}
|
||||
RED.nodes.registerType("xiaomi-gateway", XiaomiGatewayNode);
|
||||
|
||||
// The Input Node
|
||||
function GatewayIn(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
@@ -65,6 +64,9 @@ module.exports = function(RED) {
|
||||
msg = { payload: jsonMsg };
|
||||
if(jsonMsg.token && node.gateway && jsonMsg.data.ip && jsonMsg.data.ip === node.gateway.ip) {
|
||||
node.gateway.lastToken = jsonMsg.token;
|
||||
if(!node.gateway.sid) {
|
||||
node.gateway.sid = jsonMsg.sid;
|
||||
}
|
||||
}
|
||||
node.send(msg);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user