forked from Mirrors/node-red-contrib-mi-devices
126 lines
4.6 KiB
HTML
126 lines
4.6 KiB
HTML
<script type="text/javascript">
|
|
RED.nodes.registerType('xiaomi-magnet', {
|
|
category: 'xiaomi',
|
|
color: '#3FADB5',
|
|
defaults: {
|
|
gateway: {value:"", type:"xiaomi-configurator"},
|
|
name: {value: ""},
|
|
sid: {value: "", required: true},
|
|
openmsg: {value: ""},
|
|
closemsg: {value: ""},
|
|
output: {value: "0"}
|
|
},
|
|
inputs: 1,
|
|
outputs: 1,
|
|
outputLabels: ["Status"],
|
|
paletteLabel: "contact",
|
|
icon: "door-icon.png",
|
|
label: function () {
|
|
return this.name || "xiaomi-magnet";
|
|
},
|
|
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);
|
|
|
|
$("#node-input-output").change(function () {
|
|
if ($(this).val() == "2") {
|
|
$(".node-input-msg").show();
|
|
} else {
|
|
$(".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('<option value="' + device.sid + '">' + device.desc + '</option>');
|
|
}
|
|
}
|
|
$('#node-input-sid').val(node.sid);
|
|
},
|
|
oneditsave: function() {
|
|
var node = this;
|
|
node.sid = $("#node-input-sid").val();
|
|
}
|
|
});
|
|
</script>
|
|
|
|
<script type="text/x-red" data-template-name="xiaomi-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>
|
|
<div class="form-row">
|
|
<label for="node-input-output"><i class="icon-tag"></i> Output</label>
|
|
<select id="node-input-output" style="width:70%;">
|
|
<option value="0">Full data</option>
|
|
<option value="1">Just values</option>
|
|
<option value="2">Template</option>
|
|
</select>
|
|
</div>
|
|
<div class="form-row node-input-msg">
|
|
<label for="node-input-openmsg"><i class="fa fa-circle-o-notch"></i> Open msg</label>
|
|
<input type="text" id="node-input-openmsg">
|
|
</div>
|
|
<div class="form-row node-input-msg">
|
|
<label for="node-input-closemsg"><i class="fa fa-circle-o"></i> Close msg</label>
|
|
<input type="text" id="node-input-closemsg">
|
|
</div>
|
|
</script>
|
|
|
|
<script type="text/x-red" data-help-name="xiaomi-magnet">
|
|
<p>The Xiaomi contact sensor node</p>
|
|
|
|
<dl class="message-properties">
|
|
<dt class="mandatory">Gateway</dt>
|
|
<dd>The Gateway configuration node this sensor is attached.</dd>
|
|
<dt class="optional">Name</dt>
|
|
<dd>A descriptive name for this sensor.</dd>
|
|
<dt class="mandatory">Device</dt>
|
|
<dd>The device to associate this node with. This device is configured in the Gateway configuration.</dd>
|
|
<dt class="mandatory">Output</dt>
|
|
<dd>Three output types are supported:</dd>
|
|
<ul>
|
|
<li>Full data</li>
|
|
<li>Just values</li>
|
|
<li>Template</li>
|
|
</ul>
|
|
<dt class="mandatory">Full data</dt>
|
|
<dd>Passes the complete object received from the gateway. Use this if you need the raw data.</dd>
|
|
<dt class="mandatory">Just values</dt>
|
|
<dd>Only passes the values <code>open</code> or <code>close</code></dd>
|
|
<dt class="mandatory">Template</dt>
|
|
<dd>Use your own template to pass the values on. The template can contain <a href="http://mustache.github.io/mustache.5.html">mustache-style</a> tags.
|
|
Any property from the data section of the full object can be used.</dd>
|
|
</dl>
|
|
<p>Sample message:</p>
|
|
<p><pre>
|
|
{
|
|
cmd: "read_ack"
|
|
model: "magnet"
|
|
sid: "158d000112fb5d"
|
|
short_id: 50301
|
|
data: "{
|
|
"voltage":3015,
|
|
"status":"close"
|
|
}"
|
|
}</pre></p>
|
|
|
|
</script>
|