node-red-contrib-deconz
Version:
deCONZ connectivity nodes for node-red
90 lines (84 loc) • 3.74 kB
HTML
<script type="text/x-red" data-template-name="deconz-battery">
<link rel="stylesheet" href="deconz/static/css/multiple-select.css" type="text/css" />
<link rel="stylesheet" href="deconz/static/css/common.css" type="text/css" />
<div class="form-row">
<label for="node-input-name" class="l-width"><i class="icon-tag"></i> <span data-i18n="label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]placeholder.name">
</div>
<div class="form-row">
<label for="node-input-server" class="l-width"><i class="fa fa-globe"></i> <span data-i18n="label.server"></span></label>
<input type="text" id="node-input-server">
</div>
<div class="form-row">
<label for="node-input-device" class="l-width"><i class="fa fa-crosshairs"></i> <span data-i18n="label.device"></span></label>
<select id="node-input-device" class="s-width" data-i18n="[placeholder]multiselect.none_selected"></select>
</div>
<div class="form-row">
<label for="force-refresh" class="l-width"><i class="fa fa-refresh"></i> <span data-i18n="label.refresh"></span></label>
<a class="red-ui-button s-width" id="force-refresh" name="force-refresh"><span data-i18n="label.refresh_devices_list"></span></a>
</div>
<div class="form-row">
<label for='node-input-outputAtStartup' class="l-width"><i class='fa fa-share-square'></i> <span data-i18n="label.start_output"></span></label>
<input type="checkbox" id="node-input-outputAtStartup" checked="checked" style="display: inline-block; width: auto; vertical-align: top;"> <span data-i18n="label.start_output_help"></span></input>
</div>
<div class="form-tips" data-i18n="[html]tip.init"></div>
</script>
<script type='text/javascript'>
RED.nodes.registerType('deconz-battery', {
category: 'deCONZ',
color: '#f7aa3f',
defaults: {
name: {
value: ""
},
server: {
type: "deconz-server",
required: true
},
device: {
value: null,
required: true
},
device_name: {
value: null
},
outputAtStartup: {
value: true,
required: true,
}
},
inputs: 0,
outputs: 2,
outputLabels: ["state", "homekit"],
paletteLabel: 'battery',
icon: "deconz.png",
label: function () {
var label = 'deconz-battery';
if (this.name) {
label = this.name;
} else if (typeof(this.device_name) == 'string' && this.device_name.length) {
label = this.device_name;
} else if (typeof(this.device) == 'string' && this.device.length) {
label = this.device;
}
return label;
},
oneditprepare: function () {
var node = this;
setTimeout(function(){
deconz_getItemList(node.device, '#node-input-device', {allowEmpty:true, batteryFilter:true});
}, 100); //we need small timeout, too fire change event for server select
},
oneditsave: function () {
var selectedOptions = $('#node-input-device option:selected');
if (selectedOptions) {
this.device = selectedOptions.map(function () {
return $(this).val();
});
this.device_name = deconz_filterDeviceName(selectedOptions.text());
} else {
this.device_name = this.device = null;
}
}
});
</script>