node-red-contrib-mobius-flow-dali
Version:
Node-RED nodes to work with MOBiUSFlow and DALI devices
206 lines (196 loc) • 8.98 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-connection">
<div class="form-row">
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-config-input-name">
</div>
<hr>
<div class="form-row" id="conType-select">
<label for="node-config-input-conType"><i class="fa fa-tasks"></i> Connection Type</label>
<select type="text" id="node-config-input-conType" style="display: inline-block; width: 180px; vertical-align: middle;">
<option value='deuta-enocean-connection'>Deuta EnOcean</option>
</select>
</div>
<div id="common">
<div class="form-row">
<label for="node-config-input-mobius"><i class="fa fa-globe"></i> MOBiUS</label>
<input type="text" id="node-config-input-mobius">
</div>
<hr>
<div id="circuit-message-row" class="form-row hidden" style="color:#ff0000" align="center">
<p>To select a DALI circuit service from a drop-down list, <br/>
please create a MOBiUS connection, deploy the flow, and <br />
ensure that the node-red-connector service is running. <br />
Click the Confirm Deploy button if asked.</p>
</div>
<div id="circuit-failed-message-row" class="form-row hidden" style="color:#ff0000" align="center">
<p>Failed to discover services. <br />
Please check the Debug tab for more details.</p>
</div>
<div id="remote-mobius-node-row" class="form-row">
<label for="node-config-input-hid"><i class="fa fa-tag"></i> Hub ID</label>
<input type="text" id="node-config-input-hid" placeholder="Leave blank to search locally">
</div>
<div id="circuit-busy-message-row" class="form-row hidden" style="color:#008800" align="center">
<p>Discovering services. Please wait...</p>
</div>
<div id="circuit-row">
<div class="form-row">
<label for="node-config-input-circuit"><i class="fa fa-circle-o-notch"></i> Circuit</label>
<input type="text" id="node-config-input-circuit" style="width:61%;" placeholder="HID/SID (optional name)">
<a id="node-lookup-circuit" class="searchbutton" style="vertical-align: middle"><i id="node-lookup-circuit-icon" class="fa fa-search"></i></a>
</div>
</div>
<div class="form-row">
<label for="node-config-input-timeout"><i class="fa fa-clock"></i> Mobius Connection Timeout</label>
<input type="text" id="node-config-input-timeout" placeholder="Response timeout in ms">
</div>
<div class="form-row">
<label style="width:auto" for="node-config-input-updateObjects"><i class="fa fa-arrow-up"></i> Update DALI Objects </label>
<input type="checkbox" id="node-config-input-updateObjects" style="display:inline-block; width:auto; vertical-align:top;">
</div>
</div>
<hr>
<div id="enocean-connection">
<div class="form-row">
<label for="node-config-input-deutaUID"><i class="fa fa-tag"></i> Deuta UID</label>
<input type="text" id="node-config-input-deutaUID">
</div>
<div class="form-row">
<label for="node-config-input-connectors"><i class="fa fa-tag"></i> EnOcean Connector SID(s)</label>
<input type="text" id="node-config-input-connectors" placeholder="C01, C02, ... etc.">
</div>
</div>
<div id="modbus-connection">
<div class="form-row">
<label for="node-input-localIp"><i class="fa fa-sitemap"></i> ModBus Server local IP Address</label>
<input type="text" id="node-input-localIp">
</div>
<div class="form-row">
<label for="node-input-port"><i class="fa fa-tasks"></i> Port</label>
<input type="text" id="node-input-port">
</div>
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('dali-connection', {
category: 'config',
defaults: {
name: {value: ''},
conType: {value: 'deuta-enocean-connection', required: true},
updateObjects: {value: true, required: true},
deutaUID: {value: '', required: true, validate: (v) => {
var re = /^[0-9A-Fa-f]{8}$/g;
return re.test(v)
}},
connectors: {value: '', required: true, validate: (v) => {
var re = /^(( *)(([0-9]|[A-F]){3})( *)[,])*(( *)(([0-9]|[A-F]){3})( *))$/g;
return re.test(v)
}},
circuit: {required:true, value: '', validate: (v) => {
var re = /^[0-9A-F]{6}[/][0-9A-F]{3}$/g;
return re.test(v)
}},
hid: {value: '', validate:RED.validators.regex(/((^([0-9A-F]){6}$)|^$)/)},
mobius: {type:'mobius connection', required:true},
localIp: {required:true, value:'192.168.1.40', validate: (v) => {
var re = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/g;
return re.test(v)
}},
port: {required:true, value: '502', validate: (v) => {
var re = /^((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([1-5][0-9]{4})|([0-5{0,5})|([0-9]{1,4}))$/g;
return re.test(v)
}},
timeout: {value:5000, required:true, validate:RED.validators.number()}
},
label: function() {
return this.name||"dali connection";
},
labelStyle: function() {
return this.name ? 'node_label_italic':'';
},
oneditprepare: function () {
function showConnectionTypeFields () {
if ($("#node-config-input-conType").val() === 'deuta-enocean-connection') {
$("#common").show();
$("#enocean-connection").show();
$("#modbus-connection").hide();
} else if ($("#node-config-input-conType").val() === 'deuta-modbus-connection') {
$("#common").show();
$("#modbus-connection").show();
$("#enocean-connection").hide();
} else {
$("#common").hide();
$("#modbus-connection").hide();
$("#enocean-connection").hide();
}
}
showConnectionTypeFields();
$("#node-config-input-conType").change(function() {
showConnectionTypeFields();
});
$("#circuit-busy-message-row").hide();
$("#circuit-failed-message-row").hide();
function doesMobiusServiceExist () {
let srvc = $("#node-config-input-mobius").val();
if (srvc === '_ADD_') {
$("#node-lookup-circuit").hide();
$("#circuit-message-row").show();
} else {
$("#circuit-message-row").hide();
$("#node-lookup-circuit").show();
}
}
doesMobiusServiceExist();
$("#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-config-input-mobius").val();
let mobiusHID = $("#node-config-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-config-input-circuit").autocomplete({
source: services,
minLength: 0,
close: function( event, ui ) {
$("#node-config-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>