90 lines
3.2 KiB
HTML
90 lines
3.2 KiB
HTML
<script type="text/javascript">
|
|
RED.nodes.registerType('xiaomi-plug', {
|
|
category: 'xiaomi',
|
|
color: '#3FADB5',
|
|
defaults: {
|
|
gateway: {value:"", type:"xiaomi-configurator"},
|
|
name: {value: ""},
|
|
sid: {value: "", required: true},
|
|
onmsg: {value: ""},
|
|
offmsg: {value: ""},
|
|
output: {value: "0"}
|
|
},
|
|
inputs: 1,
|
|
outputs: 2,
|
|
outputLabels: ["Status","Control"],
|
|
paletteLabel: "plug (zigbee)",
|
|
icon: "outlet-icon.png",
|
|
label: function () {
|
|
return this.name || "xiaomi-plug";
|
|
},
|
|
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 === "plug") {
|
|
$('#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-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>
|
|
<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-onmsg"><i class="fa fa-power-off"></i> On msg</label>
|
|
<input type="text" id="node-input-onmsg">
|
|
</div>
|
|
<div class="form-row node-input-msg">
|
|
<label for="node-input-offmsg"><i class="fa fa-power-off"></i> Off msg</label>
|
|
<input type="text" id="node-input-offmsg">
|
|
</div>
|
|
</script>
|
|
|
|
<script type="text/x-red" data-help-name="xiaomi-plug">
|
|
<p>A simple node that converts the message payloads into a ON or OFF message</p>
|
|
</script>
|