Skip to content

Commit

Permalink
rpc-event autocompletion (fix #18)
Browse files Browse the repository at this point in the history
  • Loading branch information
hobbyquaker committed Aug 31, 2018
1 parent 9d15f3d commit ca8e856
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 104 deletions.
8 changes: 7 additions & 1 deletion nodes/ccu-connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ module.exports = function (RED) {
res.status(200).send(JSON.stringify({
channelNames: config.channelNames,
metadata: config.metadata,
paramsetDescriptions: config.paramsetDescriptions
paramsetDescriptions: config.paramsetDescriptions,
rooms: config.rooms,
functions: config.functions
}));
}
} else {
Expand Down Expand Up @@ -479,7 +481,9 @@ module.exports = function (RED) {
if (err) {
reject(err);
} else {
this.rooms = [];
res.forEach(room => {
this.rooms.push(room.name);
room.channels.forEach(chId => {
const regaChannel = this.getEntry(this.regaChannels, 'id', chId);
const address = regaChannel && regaChannel.address;
Expand All @@ -505,7 +509,9 @@ module.exports = function (RED) {
if (err) {
reject(err);
} else {
this.functions = [];
res.forEach(func => {
this.functions.push(func.name);
func.channels.forEach(chId => {
const regaChannel = this.getEntry(this.regaChannels, 'id', chId);
const address = regaChannel && regaChannel.address;
Expand Down
143 changes: 42 additions & 101 deletions nodes/ccu-rpc-event.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
}

$nodeInputCcuConfig.change(() => {
console.log('$nodeInputCcuConfig change');
loadIfaces(this.iface, () => {
ifacesLoaded = true;
$nodeInputIface.removeAttr('disabled');
Expand All @@ -100,87 +99,9 @@
}

$('#node-input-iface').change(() => {
console.log('#node-input-iface change');
autocompleteDevices();
});

$('#node-input-rooms').autocomplete({
source: [],
close: () => {

},
delay: 0,
minLength: 0
});

$('#node-input-functions').autocomplete({
source: [],
close: () => {

},
delay: 0,
minLength: 0
});

$('#node-input-device').autocomplete({
source: [],
close: () => {

},
delay: 0,
minLength: 0
});

$('#node-input-deviceName').autocomplete({
source: [],
close: () => {

},
delay: 0,
minLength: 0
});

$('#node-input-deviceType').autocomplete({
source: [],
close: () => {

},
delay: 0,
minLength: 0
});
$('#node-input-channel').autocomplete({
source: [],
close: () => {

},
delay: 0,
minLength: 0
});
$('#node-input-channelName').autocomplete({
source: [],
close: () => {

},
delay: 0,
minLength: 0
});
$('#node-input-channelType').autocomplete({
source: [],
close: () => {

},
delay: 0,
minLength: 0
});
$('#node-input-datapoint').autocomplete({
source: [],
close: () => {

},
delay: 0,
minLength: 0
});

$('.filter').each(function () {
const id = $(this).prop('id');
const $type = $('#' + id + 'Rx');
Expand All @@ -190,28 +111,47 @@
$this.typedInput({
typeField: $type,
types: ['str', 're']
})
.typedInput('width', '70%')
.on('change', (type, value) => {
if (value === 're') {
$this.autocomplete('disable');
} else {
$this.autocomplete('enable');
}
});
}).typedInput('width', '70%');

$this.parent().find('.red-ui-typedInput-input input').autocomplete({
source: [],
close: () => {

},
delay: 0,
minLength: 0
});

$this.on('change', (type, value) => {
if (value === 're') {
$this.parent().find('.red-ui-typedInput-input input').autocomplete('disable');
} else {
$this.parent().find('.red-ui-typedInput-input input').autocomplete('enable');
}
});
});

function autocompleteRoomsFunctions() {
if (!data) {
return;
}
$('#node-input-rooms').autocomplete('option', 'source', data.rooms);
$('#node-input-functions').autocomplete('option', 'source', data.functions);
$('#node-input-rooms').parent().find('.red-ui-typedInput-input input').autocomplete('option', 'source', data.rooms);
$('#node-input-functions').parent().find('.red-ui-typedInput-input input').autocomplete('option', 'source', data.functions);
}

function paramsetName(device, paramset) {
function paramsetName(iface, device, paramset) {
let cType = '';
let d;
if (device) {
return (device.PARENT_TYPE ? device.PARENT_TYPE + '/' : '') + device.VERSION + '/' + device.TYPE + '/' + paramset;
if (device.PARENT) {
// channel
cType = device.TYPE;
d = data.metadata.devices[iface][device.PARENT];
} else {
// device
d = device;
}
return [iface, d.TYPE, d.FIRMWARE, d.VERSION, cType, paramset].join('/');
}
}

Expand All @@ -229,6 +169,7 @@
channelType: [],
datapoint: []
};
console.log('autocompleteDevices', iface);

function composeLists(iface) {
if (!data.metadata.devices[iface]) {
Expand All @@ -243,7 +184,7 @@
lists.channelType.push(data.metadata.devices[iface][device].TYPE);
}

const psName = paramsetName(data.metadata.devices[iface][device], 'VALUES');
const psName = paramsetName(iface, data.metadata.devices[iface][device], 'VALUES');
if (data.paramsetDescriptions[psName]) {
Object.keys(data.paramsetDescriptions[psName]).forEach(datapoint => {
if (!lists.datapoint.includes(datapoint)) {
Expand All @@ -259,6 +200,14 @@
}
}
});

$('#node-input-device').parent().find('.red-ui-typedInput-input input').autocomplete('option', 'source', lists.device);
$('#node-input-deviceName').parent().find('.red-ui-typedInput-input input').autocomplete('option', 'source', lists.deviceName);
$('#node-input-deviceType').parent().find('.red-ui-typedInput-input input').autocomplete('option', 'source', lists.deviceType);
$('#node-input-channel').parent().find('.red-ui-typedInput-input input').autocomplete('option', 'source', lists.channel);
$('#node-input-channelName').parent().find('.red-ui-typedInput-input input').autocomplete('option', 'source', lists.channelName);
$('#node-input-channelType').parent().find('.red-ui-typedInput-input input').autocomplete('option', 'source', lists.channelType);
$('#node-input-datapoint').parent().find('.red-ui-typedInput-input input').autocomplete('option', 'source', lists.datapoint);
}

if (iface) {
Expand All @@ -268,14 +217,6 @@
composeLists(iface);
});
}

$('#node-input-device').autocomplete('option', 'source', lists.device);
$('#node-input-deviceName').autocomplete('option', 'source', lists.deviceName);
$('#node-input-deviceType').autocomplete('option', 'source', lists.deviceType);
$('#node-input-channel').autocomplete('option', 'source', lists.channel);
$('#node-input-channelName').autocomplete('option', 'source', lists.channelName);
$('#node-input-channelType').autocomplete('option', 'source', lists.channelType);
$('#node-input-datapoint').autocomplete('option', 'source', lists.datapoint);
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-ccu",
"version": "1.4.0",
"version": "1.4.1",
"description": "Node-RED Nodes for the Homematic CCU",
"repository": "https://github.com/hobbyquaker/node-red-contrib-ccu",
"keywords": [
Expand Down

0 comments on commit ca8e856

Please sign in to comment.