node-red-contrib-mobius-flow-dali
Version:
Node-RED nodes to work with MOBiUSFlow and DALI devices
231 lines (220 loc) • 10.1 kB
HTML
<!--
Copyright (C) 2020, IAConnects Technology Limited
All Rights Reserved
ALL INFORMATION CONTAINED HEREIN IS, AND REMAINS
THE PROPERTY OF IACONNECTS TECHNOLOGY LIMITED AND ITS SUPPLIERS,
IF ANY. THE INTELLECTUAL AND TECHNICAL CONCEPTS CONTAINED
HEREIN ARE PROPRIETARY TO IACONNECTS TECHNOLOGY LIMITED
AND ITS SUPPLIERS AND ARE PROTECTED BY TRADE SECRET OR COPYRIGHT LAW.
DISSEMINATION OF THIS INFORMATION OR REPRODUCTION OF THIS MATERIAL
IS STRICTLY FORBIDDEN UNLESS PRIOR WRITTEN PERMISSION IS OBTAINED
FROM IACONNECTS TECHNOLOGY LIMITED.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
-->
<script type="text/html" data-template-name="dali emergency query command generator">
<div class="form-row">
<label for="node-input-daliConnection" style="width: 160px;"><i class="fa fa-globe"></i> DALI Connection</label>
<select type="text" id="node-input-daliConnection" style="display: inline-block; width: 300px; vertical-align: middle;"></select>
</div>
<div id="nocons-message-row" class="form-row" style="color:#ff0000" align="center">
<p>Please use the DALI connection manager node <br/>
to add a new DALI connection.</p>
</div>
<hr>
<div class="form-row">
<label for="node-input-command" style="width: 160px;"><i class="fa fa-terminal"></i> Command Type</label>
<select name='commandSelect' type="text" id="node-input-command" style="display: inline-block; width: 300px; vertical-align: middle;">
<option value='' disabled selected>Select a command...</option>
<option value='241'>Query Battery Charge</option>
<option value='243'>Query Duration Test Result</option>
<option value='245'>Query Lamp Total Operation Time</option>
<option value='250'>Query Emergency Mode</option>
<option value='251'>Query Features</option>
<option value='252'>Query Failure Mode</option>
<option value='253'>Query Emergency Status</option>
</select>
</div>
<div class="form-row">
<label for="node-input-selectionMethod" style="width: 160px;"><i class="fa fa-hand-pointer-o"></i> Selection Method</label>
<select type="text" id="node-input-selectionMethod" style="display: inline-block; width: 300px; vertical-align: middle;">
<option value='ins'>By Object Instance</option>
<option value='addr'>By DALI Address</option>
</select>
</div>
<div class="form-row">
<label id ="insLabel" for="node-input-shortAddress" style="width: 160px;"><i class="fa fa-list-ol"></i> Object Instances</label>
<label id = "daliLabel" for="node-input-shortAddress" style="width: 160px;"><i class="fa fa-sitemap"></i> DALI Addresses</label>
<input type="text" id="node-input-shortAddress" style="width: 300px;">
</div>
<hr>
<div class="form-row">
<label for="node-input-name" style="width: 160px;"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" style="width: 300px;">
</div>
</script>
<script type="text/javascript">
function getLabel(conNode) {
return RED.nodes.node(conNode).name
}
RED.nodes.registerType('dali emergency query command generator', {
category: 'dali',
color: '#88cc00',
defaults: {
name: {value: ''},
daliConnection: {value: "", required: true},
command: {required:true, value: '', validate:RED.validators.regex(/^[0-9]{3}$/)},
shortAddress: {required:true, value: '0001', validate: (v) => {
let re;
switch ($("#node-input-selectionMethod").val()) {
case 'ins':
re = /^(([0]{2}([0-3]([0-9]|[A-F])))([-]([0]{2}([0-3]([0-9]|[A-F])))|))((|[,](|[ ])((([0]{2}([0-3]([0-9]|[A-F])))([-]([0]{2}([0-3]([0-9]|[A-F])))|))))+)$/g;
return re.test(v);
break;
case 'addr':
re = /^(([0-9]|[1-5][0-9]|[6][0-3])([-]([0-9]|[1-5][0-9]|[6][0-3])|))((|[,](|[ ])((([0-9]|[1-5][0-9]|[6][0-3])([-]([0-9]|[1-5][0-9]|[6][0-3])|))))+)$/g;
return re.test(v);
break;
}
return true;
}},
selectionMethod: {value: 'ins', required: true}
},
inputs: 1,
outputs: 0,
icon: 'running-man.png',
align: 'left',
paletteLabel: 'dali send emergency query',
label: function() {
const queryLookup = {
241: 'Query Battery Charge',
243: 'Query Duration Test Result',
245: 'Query Lamp Total Operation Time',
250: 'Query Emergency Mode',
251: 'Query Features',
252: 'Query Failure Mode',
253: 'Query Emergency Status'
}
let connectionLabel;
if (this.daliConnection !== '') {
connectionLabel = getLabel(this.daliConnection);
}
if (queryLookup[parseInt(this.command)] !== undefined) {
if (connectionLabel !== undefined) {
return this.name||`${queryLookup[parseInt(this.command)]} - ${connectionLabel}`;
} else {
return this.name||`${queryLookup[parseInt(this.command)]}`;
}
} else {
return this.name||`DALI Send Emergency Query`;
}
},
labelStyle: function() {
return this.name ? 'node_label_italic':'';
},
oneditprepare: function () {
let node = this;
RED.nodes.eachConfig((n) => {
if (n.type === 'dali-connection') {
$("#node-input-daliConnection").append($("<option></option>").val(n.id).text(n.name));
$("#nocons-message-row").hide();
}
});
$("#node-input-daliConnection").val(node.daliConnection);
$("#circuit-busy-message-row").hide();
$("#circuit-failed-message-row").hide();
function doesMobiusServiceExist () {
let srvc = $("#node-input-mobius").val();
if (srvc === '_ADD_') {
$("#node-lookup-circuit").hide();
$("#circuit-message-row").show();
} else {
$("#circuit-message-row").hide();
$("#node-lookup-circuit").show();
}
}
doesMobiusServiceExist();
function updateSelectionLabel() {
if($("#node-input-selectionMethod").val() === 'ins') {
$("#insLabel").show();
$("#daliLabel").hide();
} else {
$("#insLabel").hide();
$("#daliLabel").show();
}
}
updateSelectionLabel()
$("#node-input-selectionMethod").change(function() {
updateSelectionLabel();
});
$("#node-lookup-circuit").click(function() {
$("#node-lookup-circuit").addClass('disabled');
$("#circuit-row").hide();
$("#circuit-busy-message-row").show();
$("#circuit-failed-message-row").hide();
let mobiusSrvc = $("#node-input-mobius").val();
let mobiusHID = $("#node-input-hid").val();
let mobiusSPID = "0032";
$.getJSON(`mservicediscover?mobius=${mobiusSrvc}&hid=${mobiusHID}&spid=${mobiusSPID}`,function(services) {
$("#node-lookup-circuit").removeClass('disabled');
$("#circuit-busy-message-row").hide();
$("#circuit-row").show();
$("#node-input-circuit").autocomplete({
source: services,
minLength: 0,
close: function( event, ui ) {
$("#node-input-circuit").autocomplete('destroy');
}
}).autocomplete('search','');
})
.fail((err) => {
$("#node-lookup-circuit").removeClass('disabled');
$("#circuit-busy-message-row").hide();
$("#circuit-row").show();
$("#circuit-failed-message-row").show();
});
});
}
});
</script>
<script type="text/html" data-help-name="dali emergency query command generator">
<p>MOBiUS DALI Emergency Query Command Generator.</p>
<h3>Configuration Page</h3>
<dl class="message-properties">
<dt>DALI Connection <span class="property-type">connection</span></dt>
<dd>The connection to an instance of the DALI circuit service representing the working DALI circuit.</dd>
<dt>Command Type <span class="property-type">choice</span></dt>
<dd>The DALI command to be generated.</dd>
<dt>Selection Method <span class="property-type">choice</span></dt>
<dd>The method to select DALI fittings.</dd>
<dt>Addresses / Instances <span class="property-type">number</span></dt>
<dd>The list of DALI short addresses (0-63) or Mobius object instances (0001-003F).</dd>
</dl>
<h3>Input: </h3>
<dl class="message-properties">
<dd>Any input message will trigger the node to generate the set command.</dd>
</dl>
<h3>Details</h3>
<h4>Overview</h4>
<p>Generates DALI commands relating to emergency querying. Does not include DALI emergency control commands.
The node will cycle through the selected short address range, sending a query command to next short address on every input message.
</p>
<h4>Address Range</h4>
<p>Short address range to be input in any valid format involving commas and dashes
e.g. ( 0-63 ) or ( 0,1 ) or ( 0, 1, 10-20 ). Examples involving any address < 0 or > 63 are invalid.
examples starting or ending in a comma or dash are invalid e.g. ( ,1 ) or ( 1, 2, ) or ( 1, 2, 3-5, 8- ).
Any example containing letters, symbols or further punctuation are invalid.
The same principle applies to instance selection e.g. (0001-0005, 0008) etc.</p>
<p align="center" style="color:#000080">iaconnects © 2020</p>
<br>
<p align="center" style="color:#000080">ER 2020</p>
</script>