node-red-contrib-mobius-flow-dali
Version:
Node-RED nodes to work with MOBiUSFlow and DALI devices
195 lines (194 loc) • 7.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.UngroupedAddressList = exports.MasterAddressList = exports.GroupAddressList = exports.ShortAddressList = exports.populateCollectionLists = void 0;
const nodeRedUtilities = require('@ia/node-red-utilities');
function populateCollectionLists(configGroups, selectionMethod, getNode, shortAddressList, groupAddressList, masterAddressList, ungroupedAddressList) {
let i;
let j;
/*
Build groups array
Each element represents a dali group in the following form
{
groupNum: (The dali group address)
contents: (An array of the short address within the group, e.g. [0, 1, 5, 63])
connectionId: (The node id of the dali master connection config node)
masterNum: (Number representing dali master associated with dali group instance, coressponding to masters array)
}
Also build dali masters array, elements in the following form
{
connectionId: (The node id of the dali master connection config node)
master: (The dali master connection itself)
mobius: (Service connection to mobius associated with each dali master instance, hub agnostic)
}
*/
for (i = 0; i < configGroups.length; i++) {
let contents = [];
if (selectionMethod === 'ins') {
contents = nodeRedUtilities.splitInstanceSelection(configGroups[i].short);
}
else {
contents = nodeRedUtilities.MSWordPrintingPageSelectionFormatDecode(configGroups[i].short);
}
let k = 0;
let groupAllreadyAdded = false;
for (k = 0; k < groupAddressList.groups.length; k++) {
if (parseInt(configGroups[i].groupNum, 10) === groupAddressList.groups[k].groupNum
&& configGroups[i].con === groupAddressList.groups[k].connectionId) {
groupAddressList.groups[k].contents =
groupAddressList.groups[k].contents.concat(contents);
groupAllreadyAdded = true;
k = groupAddressList.groups.length;
}
}
if (!groupAllreadyAdded) {
k = 0;
let masterFound = false;
for (k = 0; k < masterAddressList.masters.length; k++) {
if (masterAddressList.masters[k].connectionId === configGroups[i].con) {
masterFound = true;
groupAddressList.groups.push({
groupNum: parseInt(configGroups[i].groupNum, 10),
contents: contents,
connectionId: configGroups[i].con,
masterNum: k,
masterConnection: null
});
k = masterAddressList.masters.length;
}
}
if (!masterFound) {
masterAddressList.masters.push({
connectionId: configGroups[i].con,
master: getNode(configGroups[i].con).connection,
mobius: getNode(configGroups[i].con).serviceConn
});
groupAddressList.groups.push({
groupNum: parseInt(configGroups[i].groupNum, 10),
contents: contents,
connectionId: configGroups[i].con,
masterNum: masterAddressList.masters.length - 1,
masterConnection: null
});
}
}
}
// Remove duplicate entrys from each short address content array in each group
// Point masterConnection to respective master
for (i = 0; i < groupAddressList.groups.length; i++) {
groupAddressList.groups[i].contents = [...new Set(groupAddressList.groups[i].contents)];
groupAddressList.groups[i].masterConnection = masterAddressList.masters[groupAddressList.groups[i].masterNum];
}
/*
Populate list of short addresses within collection
List of short address objects in the following form
{
addr: (The dali short address)
group: (The dali group address with short address falls within)
masterNum: (Number representing dali master associated with dali device, coressponding to masters array)
}
*/
for (i = 0; i < groupAddressList.groups.length; i++) {
for (j = 0; j < groupAddressList.groups[i].contents.length; j++) {
shortAddressList.shortAddresses.push({
addr: groupAddressList.groups[i].contents[j],
group: groupAddressList.groups[i].groupNum,
masterConnection: groupAddressList.groups[i].masterConnection
});
if (groupAddressList.groups[i].groupNum < 0) {
ungroupedAddressList.ungroupedAddresses.push({
addr: groupAddressList.groups[i].contents[j],
masterConnection: groupAddressList.groups[i].masterConnection
});
}
}
}
}
exports.populateCollectionLists = populateCollectionLists;
class ShortAddressList {
shortAddresses = [];
shortAddressIterator() {
let nextIndex = 0;
let iterationCount = 0;
const self = this;
const interator = {
next: function () {
let result;
if (nextIndex < self.shortAddresses.length) {
result = { value: self.shortAddresses[nextIndex], done: false };
nextIndex += 1;
iterationCount++;
return result;
}
return { value: iterationCount, done: true };
}
};
return interator;
}
}
exports.ShortAddressList = ShortAddressList;
class GroupAddressList {
groups = [];
groupsIterator() {
let nextIndex = 0;
let iterationCount = 0;
const self = this;
const interator = {
next: function () {
let result;
if (nextIndex < self.groups.length) {
result = { value: self.groups[nextIndex], done: false };
nextIndex += 1;
iterationCount++;
return result;
}
return { value: iterationCount, done: true };
}
};
return interator;
}
}
exports.GroupAddressList = GroupAddressList;
class MasterAddressList {
masters = [];
mastersIterator() {
let nextIndex = 0;
let iterationCount = 0;
const self = this;
const interator = {
next: function () {
let result;
if (nextIndex < self.masters.length) {
result = { value: self.masters[nextIndex], done: false };
nextIndex += 1;
iterationCount++;
return result;
}
return { value: iterationCount, done: true };
}
};
return interator;
}
}
exports.MasterAddressList = MasterAddressList;
class UngroupedAddressList {
ungroupedAddresses = [];
ungroupedAddressIterator() {
let nextIndex = 0;
let iterationCount = 0;
const self = this;
const interator = {
next: function () {
let result;
if (nextIndex < self.ungroupedAddresses.length) {
result = { value: self.ungroupedAddresses[nextIndex], done: false };
nextIndex += 1;
iterationCount++;
return result;
}
return { value: iterationCount, done: true };
}
};
return interator;
}
}
exports.UngroupedAddressList = UngroupedAddressList;