doc(main): update documentation and flows
This commit is contained in:
59
dist/nodes/gateway-subdevices/All.js
vendored
Normal file
59
dist/nodes/gateway-subdevices/All.js
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const constants_1 = require("../constants");
|
||||
exports.default = (RED) => {
|
||||
class All {
|
||||
static getOnlyModelsValue(input) {
|
||||
var cleanOnlyModels = [];
|
||||
input.forEach((value) => {
|
||||
cleanOnlyModels = cleanOnlyModels.concat(value.split(','));
|
||||
});
|
||||
return cleanOnlyModels;
|
||||
}
|
||||
constructor(props) {
|
||||
RED.nodes.createNode(this, props);
|
||||
this.gateway = RED.nodes.getNode(props.gateway);
|
||||
this.onlyModels = All.getOnlyModelsValue(props.onlyModels || []);
|
||||
this.excludedSids = props.excludedSids;
|
||||
this.setMessageListener();
|
||||
}
|
||||
setMessageListener() {
|
||||
this.on('input', (msg) => {
|
||||
if (this.gateway) {
|
||||
// Filter input
|
||||
if (msg.payload && msg.payload.model && msg.payload.sid) {
|
||||
if (!this.isDeviceValid(msg.payload)) {
|
||||
msg = null;
|
||||
}
|
||||
this.send(msg);
|
||||
}
|
||||
else {
|
||||
Object.keys(this.gateway.deviceList || {})
|
||||
.filter((sid) => this.isDeviceValid(sid))
|
||||
.forEach((sid) => {
|
||||
let curMsg = Object.assign({}, msg);
|
||||
curMsg.sid = sid;
|
||||
curMsg.gateway = this.gateway;
|
||||
this.send(curMsg);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
isDeviceValid(sid) {
|
||||
if ((!this.onlyModels || this.onlyModels.length == 0) && (!this.excludedSids || this.excludedSids.length == 0)) {
|
||||
return true;
|
||||
}
|
||||
let device = this.gateway.deviceList[sid];
|
||||
// Is excluded
|
||||
if ((this.excludedSids && this.excludedSids.length != 0) && this.excludedSids.indexOf(sid) >= 0) {
|
||||
return false;
|
||||
}
|
||||
if ((this.onlyModels && this.onlyModels.length != 0) && this.onlyModels.indexOf(device.internalModel) >= 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
RED.nodes.registerType(`${constants_1.Constants.NODES_PREFIX}-all`, All);
|
||||
};
|
||||
45
dist/nodes/gateway-subdevices/GatewaySubdevice.js
vendored
Normal file
45
dist/nodes/gateway-subdevices/GatewaySubdevice.js
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const constants_1 = require("../constants");
|
||||
exports.default = (RED, type) => {
|
||||
class GatewayDevice {
|
||||
constructor(props) {
|
||||
RED.nodes.createNode(this, props);
|
||||
this.gateway = RED.nodes.getNode(props.gateway);
|
||||
this.sid = props.sid;
|
||||
this.status({ fill: "grey", shape: "ring", text: "battery - na" });
|
||||
this.setMessageListener();
|
||||
}
|
||||
setMessageListener() {
|
||||
if (this.gateway) {
|
||||
this.on('input', (msg) => {
|
||||
let payload = msg.payload;
|
||||
// Input from gateway
|
||||
if (payload.sid) {
|
||||
if (payload.sid == this.sid) {
|
||||
let batteryLevel = payload.batteryLevel;
|
||||
var status = {
|
||||
fill: "green", shape: "dot",
|
||||
text: "battery - " + batteryLevel + "%"
|
||||
};
|
||||
if (batteryLevel < 10) {
|
||||
status.fill = "red";
|
||||
}
|
||||
else if (batteryLevel < 45) {
|
||||
status.fill = "yellow";
|
||||
}
|
||||
this.status(status);
|
||||
this.send([msg]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
msg.sid = this.sid;
|
||||
msg.gateway = this.gateway;
|
||||
this.send(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
RED.nodes.registerType(`${constants_1.Constants.NODES_PREFIX}-${type}`, GatewayDevice);
|
||||
};
|
||||
34
dist/nodes/gateway-subdevices/Plug.js
vendored
Normal file
34
dist/nodes/gateway-subdevices/Plug.js
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const constants_1 = require("../constants");
|
||||
exports.default = (RED) => {
|
||||
class Plug {
|
||||
constructor(props) {
|
||||
RED.nodes.createNode(this, props);
|
||||
this.gateway = RED.nodes.getNode(props.gateway);
|
||||
this.status({ fill: "grey", shape: "ring", text: "status" });
|
||||
}
|
||||
setListener() {
|
||||
if (this.gateway) {
|
||||
this.on('input', (msg) => {
|
||||
var payload = msg.payload;
|
||||
if (payload.sid) {
|
||||
if (payload.sid == this.sid) {
|
||||
if (payload.data.status && payload.data.status == "on") {
|
||||
this.status({ fill: "green", shape: "dot", text: "on" });
|
||||
}
|
||||
else if (payload.data.status && payload.data.status == "off") {
|
||||
this.status({ fill: "red", shape: "dot", text: "off" });
|
||||
}
|
||||
this.send(msg);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.send(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
RED.nodes.registerType(`${constants_1.Constants.NODES_PREFIX}-plug`, Plug);
|
||||
};
|
||||
BIN
dist/nodes/gateway-subdevices/icons/door-icon.png
vendored
Normal file
BIN
dist/nodes/gateway-subdevices/icons/door-icon.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.6 KiB |
BIN
dist/nodes/gateway-subdevices/icons/mi-all.png
vendored
Normal file
BIN
dist/nodes/gateway-subdevices/icons/mi-all.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
BIN
dist/nodes/gateway-subdevices/icons/mi-switch.png
vendored
Normal file
BIN
dist/nodes/gateway-subdevices/icons/mi-switch.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 842 B |
BIN
dist/nodes/gateway-subdevices/icons/motion-icon.png
vendored
Normal file
BIN
dist/nodes/gateway-subdevices/icons/motion-icon.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.7 KiB |
BIN
dist/nodes/gateway-subdevices/icons/outlet-icon.png
vendored
Normal file
BIN
dist/nodes/gateway-subdevices/icons/outlet-icon.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
BIN
dist/nodes/gateway-subdevices/icons/thermometer-icon.png
vendored
Normal file
BIN
dist/nodes/gateway-subdevices/icons/thermometer-icon.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
729
dist/nodes/gateway-subdevices/index.html
vendored
Normal file
729
dist/nodes/gateway-subdevices/index.html
vendored
Normal file
@@ -0,0 +1,729 @@
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('mi-devices-all', {
|
||||
category: 'xiaomi',
|
||||
color: '#3FADB5',
|
||||
defaults: {
|
||||
gateway: {value:"", type:"mi-devices-gateway configurator"},
|
||||
name: {value: ""},
|
||||
onlyModels: {value: []},
|
||||
excludedSids: { value: []}
|
||||
},
|
||||
inputs: 1,
|
||||
outputs: 1,
|
||||
outputLabels: ["All devices"],
|
||||
paletteLabel: "all",
|
||||
icon: "mi-all.png",
|
||||
label: function () {
|
||||
return this.name || "xiaomi-all";
|
||||
},
|
||||
oneditprepare: function() {
|
||||
var node = this;
|
||||
|
||||
function getOnlyModelsValue(input) {
|
||||
var cleanOnlyModels = [];
|
||||
input.forEach(function(value) {
|
||||
cleanOnlyModels = cleanOnlyModels.concat(value.split(','));
|
||||
});
|
||||
return cleanOnlyModels;
|
||||
}
|
||||
|
||||
function changeGateway(gateway, onlyModels, excludedSids) {
|
||||
var configNodeID = gateway || $('#node-input-gateway').val();
|
||||
if (configNodeID) {
|
||||
var configNode = RED.nodes.node(configNodeID);
|
||||
if(configNode) {
|
||||
onlyModels = getOnlyModelsValue(onlyModels || $('#node-input-onlyModels').val() || []);
|
||||
excludedSids = excludedSids || $('#node-input-excludedSids').val() || [];
|
||||
$('#node-input-excludedSids').empty();
|
||||
for (sid in configNode.deviceList) {
|
||||
var device = configNode.deviceList[sid];
|
||||
if (onlyModels.length == 0 || onlyModels.indexOf(device.internalModel) >= 0) {
|
||||
var option = $('<option value="' + sid + '">' + device.name + '</option>');
|
||||
if(excludedSids && excludedSids.indexOf(sid) >= 0) {
|
||||
option.prop('selected', true);
|
||||
}
|
||||
$('#node-input-excludedSids').append(option);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
changeGateway(this.gateway, this.onlyModels, this.excludedSids);
|
||||
$("#node-input-gateway, #node-input-onlyModels").change(function () {
|
||||
changeGateway();
|
||||
});
|
||||
},
|
||||
oneditsave: function() {
|
||||
if(!$('#node-input-onlyModels').val()) {
|
||||
this.onlyModels = [];
|
||||
}
|
||||
if(!$('#node-input-excludedSids').val()) {
|
||||
this.excludedSids = [];
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-template-name="mi-devices-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>
|
||||
<hr />
|
||||
<h5>Filters</h5>
|
||||
<div class="form-row">
|
||||
<label for="node-input-onlyModels"><i class="icon-tag"></i> Only</label>
|
||||
<select multiple id="node-input-onlyModels">
|
||||
<option value="mi.weather">Temperature/humidty</option>
|
||||
<option value="mi.motion">Motion</option>
|
||||
<option value="mi.switch">Switches</option>
|
||||
<option value="mi.magnet">Magnets</option>
|
||||
<option value="mi.plug">Plugs</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-excludedSids"><i class="icon-tag"></i> Exclude</label>
|
||||
<select multiple id="node-input-excludedSids" size=10></select>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="mi-devices-all">
|
||||
<p>All devices registred in the gateway, except gateway itself.</p>
|
||||
|
||||
<h3>Inputs</h3>
|
||||
<dl class="message-properties">
|
||||
<dt>payload
|
||||
<span class="property-type">object</span>
|
||||
</dt>
|
||||
<dd>When use as an incoming filter node, <code>sid</code> and <code>model</code> are mandatory.</dd>
|
||||
</dl>
|
||||
|
||||
<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>
|
||||
|
||||
<h4>Details</h4>
|
||||
<p>Sample payload:</p>
|
||||
<p><pre>[
|
||||
{sid: "128d0901db1fa8", desc: "Door sensor" model: "magnet"},
|
||||
{sid: "151d0401ab2491", desc: "Heat sensor", model: "sensor_ht"},
|
||||
{sid: "658d030171427c", desc: "Button", model: "switch"}
|
||||
]</pre>
|
||||
</p>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('mi-devices-plug', {
|
||||
category: 'xiaomi',
|
||||
color: '#3FADB5',
|
||||
defaults: {
|
||||
gateway: {value:"", type:"mi-devices-gateway configurator"},
|
||||
name: {value: ""},
|
||||
sid: {value: "", required: true},
|
||||
onmsg: {value: ""},
|
||||
offmsg: {value: ""},
|
||||
output: {value: "0"}
|
||||
},
|
||||
inputs: 1,
|
||||
outputs: 1,
|
||||
paletteLabel: "plug (zigbee)",
|
||||
icon: "outlet-icon.png",
|
||||
label: function () {
|
||||
return this.name || "xiaomi-plug";
|
||||
},
|
||||
oneditprepare: function() {
|
||||
var node = this;
|
||||
|
||||
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('<option value="' + device.sid + '">' + device.desc + '</option>');
|
||||
}
|
||||
}
|
||||
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("plug");
|
||||
});
|
||||
},
|
||||
oneditsave: function() {
|
||||
var node = this;
|
||||
node.sid = $("#node-input-sid").val();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-template-name="mi-devices-plug">
|
||||
<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>
|
||||
<div class="form-row">
|
||||
<label for="node-input-sid"><i class="icon-tag"></i> Device</label>
|
||||
<select id="node-input-sid" placeholder="xiaomi gateway"></select>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="mi-devices-plug">
|
||||
<p>The Xiaomi plug (zigbee) node</p>
|
||||
|
||||
<p>This is the plug (socket) version which is attached to a Xiaomi gateway. The Wifi version is not yet supported.</p>
|
||||
<p>To switch an output you need to specify the key of the gateway in the gateway configuration; without the key
|
||||
no output can be switched. To retrieve the gateway key consult the Xiaomi Mi Home App.</p>
|
||||
|
||||
<h3>Inputs</h3>
|
||||
<dl class="message-properties">
|
||||
<dt>payload
|
||||
<span class="property-type">string | json</span>
|
||||
</dt>
|
||||
<dd>When the node is used as filter, gateway <code>plug</code> message of type <code>read_ack</code>, <code>heartbeat</code> or <code>report</code>. Or <code>on</code> or <code>off</code>.</dd>
|
||||
</dl>
|
||||
|
||||
<h3>Outputs</h3>
|
||||
<ol class="node-ports">
|
||||
<li>Status output
|
||||
<dl class="message-properties">
|
||||
<dt>payload <span class="property-type">string | json</span></dt>
|
||||
<dd>raw data, value or template.</dd>
|
||||
</dl>
|
||||
</li>
|
||||
<li>Control output
|
||||
<dl class="message-properties">
|
||||
<dt>payload <span class="property-type">json</span></dt>
|
||||
<dd>Gateway <code>write_cmd</code> to switch the output on or off.</dd>
|
||||
</dl>
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
<h4>Details</h4>
|
||||
<p>The incoming json message is parsed if the type model is <code>plug</code> and
|
||||
the <code>sid</code> matches the configured value for this device.</p>
|
||||
<p>On the input you can send the string <code>on</code> to switch the plug on. To turn it off just send the string <code>off</code></p>
|
||||
<p>Sample message:</p>
|
||||
<p><pre>{
|
||||
cmd: "write_ack"
|
||||
model: "plug"
|
||||
sid: "158d00012f1fb5"
|
||||
short_id: 47414
|
||||
data: {
|
||||
voltage:3600,
|
||||
status:"off",
|
||||
inuse:"0",
|
||||
power_consumed:"4000",
|
||||
load_power:"0"
|
||||
}
|
||||
}</pre></p>
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('mi-devices-magnet', {
|
||||
category: 'xiaomi',
|
||||
color: '#3FADB5',
|
||||
defaults: {
|
||||
gateway: {value:"", type:"mi-devices-gateway configurator"},
|
||||
name: {value: ""},
|
||||
sid: {value: "", required: true}
|
||||
},
|
||||
inputs: 1,
|
||||
outputs: 1,
|
||||
paletteLabel: "magnet",
|
||||
icon: "door-icon.png",
|
||||
label: function () {
|
||||
return this.name || "mi-devices magnet";
|
||||
},
|
||||
oneditprepare: function() {
|
||||
var node = this;
|
||||
|
||||
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 (sid in configNode.deviceList) {
|
||||
var device = configNode.deviceList[sid];
|
||||
if (device.internalModel === model) {
|
||||
$('#node-input-sid').append('<option value="' + sid + '">' + device.name + ' - ' + sid + '</option>');
|
||||
}
|
||||
}
|
||||
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("mi.magnet");
|
||||
});
|
||||
},
|
||||
oneditsave: function() {
|
||||
var node = this;
|
||||
node.sid = $("#node-input-sid").val();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-template-name="mi-devices-magnet">
|
||||
<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>
|
||||
<div class="form-row">
|
||||
<label for="node-input-sid"><i class="icon-tag"></i> Device</label>
|
||||
<select id="node-input-sid" placeholder="xiaomi gateway"></select>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="mi-devices-magnet">
|
||||
<p>The Xiaomi contact sensor node</p>
|
||||
|
||||
<h3>Inputs</h3>
|
||||
<dl class="message-properties">
|
||||
<dt>payload
|
||||
<span class="property-type">object</span>
|
||||
</dt>
|
||||
<dd>
|
||||
When the message contains a <code>sid</code> field, the node will filter the input and output only if the <code>sid</code> is the device's sid.<br>
|
||||
<hr>
|
||||
If the message doesn't contain a <code>sid</code> field, the node will be used to inject <code>sid</code> and <code>gateway</code> fields in the incoming <code>msg</code>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<h3>Outputs</h3>
|
||||
<ol class="node-ports">
|
||||
<dl class="message-properties">
|
||||
<dt>payload <span class="property-type">object</span></dt>
|
||||
<dd>Data from gateway when used as a filter (see below).</dd>
|
||||
<dt>sid <span class="property-type">string</span></dt>
|
||||
<dd>Device SID.</dd>
|
||||
<dt>gateway <span class="property-type">object</span></dt>
|
||||
<dd>The <code>mi-devices-gateway configurator</code> object where the device is registred.</dd>
|
||||
</dl>
|
||||
</ol>
|
||||
|
||||
<h4>Details</h4>
|
||||
<p>The incoming message is processed if the input <code>sid</code> matches the configured value for this device.</p>
|
||||
<p>Sample payload after incoming incoming message:</p>
|
||||
<p><pre>{
|
||||
cmd: "read_ack"
|
||||
model: "magnet"
|
||||
sid: "158d000112fb5d"
|
||||
short_id: 50301
|
||||
data: {
|
||||
voltage: 3015,
|
||||
status: "close",
|
||||
batteryLevel: 23
|
||||
}
|
||||
}</pre>
|
||||
Where <code>status</code> can be <code>"open"</code> or <code>"close"</code>, <code>batteryLevel</code> is a computed percentage of remaining battery.
|
||||
</p>
|
||||
</script>
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('mi-devices-mi.motion', {
|
||||
category: 'xiaomi',
|
||||
color: '#3FADB5',
|
||||
defaults: {
|
||||
gateway: {value:"", type:"mi-devices-gateway configurator"},
|
||||
name: {value: ""},
|
||||
sid: {value: "", required: true}
|
||||
},
|
||||
inputs: 1,
|
||||
outputs: 1,
|
||||
paletteLabel: "motion",
|
||||
icon: "motion-icon.png",
|
||||
label: function () {
|
||||
return this.name || "mi-devices mi.motion";
|
||||
},
|
||||
oneditprepare: function() {
|
||||
var node = this;
|
||||
|
||||
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 (sid in configNode.deviceList) {
|
||||
var device = configNode.deviceList[sid];
|
||||
if (device.internalModel === model) {
|
||||
$('#node-input-sid').append('<option value="' + sid + '">' + device.name + ' - ' + sid + '</option>');
|
||||
}
|
||||
}
|
||||
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("mi.motion");
|
||||
});
|
||||
},
|
||||
oneditsave: function() {
|
||||
var node = this;
|
||||
node.sid = $("#node-input-sid").val();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-template-name="mi-devices-mi.motion">
|
||||
<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>
|
||||
<div class="form-row">
|
||||
<label for="node-input-sid"><i class="icon-tag"></i> Device</label>
|
||||
<select id="node-input-sid" placeholder="xiaomi gateway"></select>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="mi-devices-mi.motion">
|
||||
<p>The Xiaomi body motion sensor node</p>
|
||||
|
||||
<h3>Inputs</h3>
|
||||
<dl class="message-properties">
|
||||
<dt>payload
|
||||
<span class="property-type">object</span>
|
||||
</dt>
|
||||
<dd>
|
||||
When the message contains a <code>sid</code> field, the node will filter the input and output only if the <code>sid</code> is the device's sid.<br>
|
||||
<hr>
|
||||
If the message doesn't contain a <code>sid</code> field, the node will be used to inject <code>sid</code> and <code>gateway</code> fields in the incoming <code>msg</code>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<h3>Outputs</h3>
|
||||
<ol class="node-ports">
|
||||
<dl class="message-properties">
|
||||
<dt>payload <span class="property-type">object</span></dt>
|
||||
<dd>Data from gateway when used as a filter (see below).</dd>
|
||||
<dt>sid <span class="property-type">string</span></dt>
|
||||
<dd>Device SID.</dd>
|
||||
<dt>gateway <span class="property-type">object</span></dt>
|
||||
<dd>The <code>mi-devices-gateway configurator</code> object where the device is registred.</dd>
|
||||
</dl>
|
||||
</ol>
|
||||
|
||||
<h4>Details</h4>
|
||||
<p>The incoming message is processed if the input <code>sid</code> matches the configured value for this device.</p>
|
||||
<p>Sample payload after incoming incoming message:</p>
|
||||
<p><pre>{
|
||||
cmd: "read_ack"
|
||||
model: "motion"
|
||||
sid: "158d00015ef56c"
|
||||
short_id: 21672
|
||||
data: {
|
||||
voltage: 3035,
|
||||
status: "motion",
|
||||
batteryLevel: 45
|
||||
}
|
||||
}</pre>
|
||||
Where <code>batteryLevel</code> is a computed percentage of remaining battery.
|
||||
</p>
|
||||
</script>
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('mi-devices-mi.weather', {
|
||||
category: 'xiaomi',
|
||||
color: '#3FADB5',
|
||||
defaults: {
|
||||
gateway: {value:"", type:"mi-devices-gateway configurator"},
|
||||
name: {value: ""},
|
||||
sid: {value: "", required: true}
|
||||
},
|
||||
inputs: 1,
|
||||
outputs: 1,
|
||||
paletteLabel: "weather",
|
||||
icon: "thermometer-icon.png",
|
||||
label: function () {
|
||||
return this.name || "mi-devices mi.weather";
|
||||
},
|
||||
oneditprepare: function() {
|
||||
var node = this;
|
||||
|
||||
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 (sid in configNode.deviceList) {
|
||||
var device = configNode.deviceList[sid];
|
||||
if (device.internalModel === model) {
|
||||
$('#node-input-sid').append('<option value="' + sid + '">' + device.name + ' - ' + sid + '</option>');
|
||||
}
|
||||
}
|
||||
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("mi.weather");
|
||||
});
|
||||
},
|
||||
oneditsave: function() {
|
||||
var node = this;
|
||||
node.sid = $("#node-input-sid").val();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-template-name="mi-devices-mi.weather">
|
||||
<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>
|
||||
<div class="form-row">
|
||||
<label for="node-input-sid"><i class="icon-tag"></i> Device</label>
|
||||
<select id="node-input-sid" placeholder="xiaomi gateway"></select>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="mi-devices-mi.weather">
|
||||
<p>The Xiaomi Humidity & Temperature sensor node</p>
|
||||
|
||||
<h3>Inputs</h3>
|
||||
<dl class="message-properties">
|
||||
<dt>payload
|
||||
<span class="property-type">object</span>
|
||||
</dt>
|
||||
<dd>
|
||||
When the message contains a <code>sid</code> field, the node will filter the input and output only if the <code>sid</code> is the device's sid.<br>
|
||||
<hr>
|
||||
If the message doesn't contain a <code>sid</code> field, the node will be used to inject <code>sid</code> and <code>gateway</code> fields in the incoming <code>msg</code>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<h3>Outputs</h3>
|
||||
<ol class="node-ports">
|
||||
<dl class="message-properties">
|
||||
<dt>payload <span class="property-type">object</span></dt>
|
||||
<dd>Data from gateway when used as a filter (see below).</dd>
|
||||
<dt>sid <span class="property-type">string</span></dt>
|
||||
<dd>Device SID.</dd>
|
||||
<dt>gateway <span class="property-type">object</span></dt>
|
||||
<dd>The <code>mi-devices-gateway configurator</code> object where the device is registred.</dd>
|
||||
</dl>
|
||||
</ol>
|
||||
|
||||
<h4>Details</h4>
|
||||
<p>The incoming message is processed if the input <code>sid</code> matches the configured value for this device.</p>
|
||||
<p>Sample payload after incoming incoming message:</p>
|
||||
<p><pre>{
|
||||
cmd: "read_ack"
|
||||
model: "weather.v1"
|
||||
sid: "158d00010b7f1b"
|
||||
short_id: 8451
|
||||
data: {
|
||||
voltage:3005,
|
||||
temperature:23.25,
|
||||
humidity:56.99,
|
||||
pressure:981.26,
|
||||
batteryLevel: 34
|
||||
}
|
||||
}</pre>
|
||||
Where <code>humidy</code> is in percents, <code>pressure</code> in kPa, <code>batteryLevel</code> is a computed percentage of remaining battery.
|
||||
</p>
|
||||
</script>
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('mi-devices-mi.switch', {
|
||||
category: 'xiaomi',
|
||||
color: '#3FADB5',
|
||||
defaults: {
|
||||
gateway: {value:"", type:"mi-devices-gateway configurator"},
|
||||
name: {value: ""},
|
||||
sid: {value: "", required: true}
|
||||
},
|
||||
inputs: 1,
|
||||
outputs: 1,
|
||||
paletteLabel: "switch",
|
||||
icon: "mi-switch.png",
|
||||
label: function () {
|
||||
return this.name || "mi-devices mi.switch";
|
||||
},
|
||||
oneditprepare: function() {
|
||||
var node = this;
|
||||
|
||||
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 (sid in configNode.deviceList) {
|
||||
var device = configNode.deviceList[sid];
|
||||
if (device.internalModel === model) {
|
||||
$('#node-input-sid').append('<option value="' + sid + '">' + device.name + ' - ' + sid + '</option>');
|
||||
}
|
||||
}
|
||||
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("mi.switch");
|
||||
});
|
||||
},
|
||||
oneditsave: function() {
|
||||
var node = this;
|
||||
node.sid = $("#node-input-sid").val();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-template-name="mi-devices-mi.switch">
|
||||
<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>
|
||||
<div class="form-row">
|
||||
<label for="node-input-sid"><i class="icon-tag"></i> Device</label>
|
||||
<select id="node-input-sid" placeholder="xiaomi gateway"></select>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="mi-devices-mi.switch">
|
||||
<p>The Xiaomi Switch sensor node</p>
|
||||
|
||||
<h3>Inputs</h3>
|
||||
<dl class="message-properties">
|
||||
<dt>payload
|
||||
<span class="property-type">object</span>
|
||||
</dt>
|
||||
<dd>
|
||||
When the message contains a <code>sid</code> field, the node will filter the input and output only if the <code>sid</code> is the device's sid.<br>
|
||||
<hr>
|
||||
If the message doesn't contain a <code>sid</code> field, the node will be used to inject <code>sid</code> and <code>gateway</code> fields in the incoming <code>msg</code>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<h3>Outputs</h3>
|
||||
<ol class="node-ports">
|
||||
<dl class="message-properties">
|
||||
<dt>payload <span class="property-type">object</span></dt>
|
||||
<dd>Data from gateway when used as a filter (see below).</dd>
|
||||
<dt>sid <span class="property-type">string</span></dt>
|
||||
<dd>Device SID.</dd>
|
||||
<dt>gateway <span class="property-type">object</span></dt>
|
||||
<dd>The <code>mi-devices-gateway configurator</code> object where the device is registred.</dd>
|
||||
</dl>
|
||||
</ol>
|
||||
|
||||
<h4>Details</h4>
|
||||
<p>The incoming message is processed if the input <code>sid</code> matches the configured value for this device.</p>
|
||||
<p>Sample payload after incoming incoming message:</p>
|
||||
<p><pre>{
|
||||
cmd: "report"
|
||||
model: "switch"
|
||||
sid: "158d000128b124"
|
||||
short_id: 56773
|
||||
data: {
|
||||
status: "click",
|
||||
batteryLevel: 23
|
||||
}
|
||||
}</pre>
|
||||
Where <code>batteryLevel</code> is a computed percentage of remaining battery.
|
||||
</p>
|
||||
</script>
|
||||
11
dist/nodes/gateway-subdevices/index.js
vendored
Normal file
11
dist/nodes/gateway-subdevices/index.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
const All_1 = require("./All");
|
||||
const Plug_1 = require("./Plug");
|
||||
const GatewaySubdevice_1 = require("./GatewaySubdevice");
|
||||
module.exports = (RED) => {
|
||||
All_1.default(RED);
|
||||
Plug_1.default(RED);
|
||||
["magnet", "motion", "sensor", "switch"].forEach((subdeviceType) => {
|
||||
GatewaySubdevice_1.default(RED, subdeviceType);
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user