Skip to content

Commit

Permalink
Merge 9e17e70 into d3846ec
Browse files Browse the repository at this point in the history
  • Loading branch information
dersimn committed Nov 19, 2020
2 parents d3846ec + 9e17e70 commit 4d51afb
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 61 deletions.
4 changes: 4 additions & 0 deletions nodes/ccu-set-value.html
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,10 @@
</div>

<div class="form-tips">
<p>
<span data-i18n="ccu-set-value.tip-message"></span>
<code>msg.device</code>, <code>msg.deviceName</code>, <code>msg.datapoint</code>, etc. …
</p>
</div>
</script>

Expand Down
123 changes: 67 additions & 56 deletions nodes/ccu-set-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,30 @@ module.exports = function (RED) {

this.ccu.register(this);

this.iface = config.iface;
this.rooms = config.rooms;
this.functions = config.functions;
this.device = config.device;
this.deviceType = config.deviceType;
this.deviceName = config.deviceName;
this.channel = config.channel;
this.channelType = config.channelType;
this.channelIndex = config.channelIndex;
this.channelName = config.channelName;
this.datapoint = config.datapoint;
this.roomsRx = config.roomsRx;
this.functionsRx = config.functionsRx;
this.deviceRx = config.deviceRx;
this.deviceTypeRx = config.deviceTypeRx;
this.deviceNameRx = config.deviceNameRx;
this.channelRx = config.channelRx;
this.channelTypeRx = config.channelTypeRx;
this.channelIndexRx = config.channelIndexRx;
this.channelNameRx = config.channelNameRx;
this.datapointRx = config.datapointRx;
this.force = config.force;
this.config = {
iface: config.iface,
rooms: config.rooms,
functions: config.functions,
device: config.device,
deviceType: config.deviceType,
deviceName: config.deviceName,
channel: config.channel,
channelType: config.channelType,
channelIndex: config.channelIndex,
channelName: config.channelName,
datapoint: config.datapoint,
roomsRx: config.roomsRx,
functionsRx: config.functionsRx,
deviceRx: config.deviceRx,
deviceTypeRx: config.deviceTypeRx,
deviceNameRx: config.deviceNameRx,
channelRx: config.channelRx,
channelTypeRx: config.channelTypeRx,
channelIndexRx: config.channelIndexRx,
channelNameRx: config.channelNameRx,
datapointRx: config.datapointRx,
force: config.force
};

this.blacklist = new Set();
this.whitelist = new Set();
Expand All @@ -62,9 +64,18 @@ module.exports = function (RED) {
}

setValues(message) {
const {config} = this;
Object.keys(config).forEach(key => {
if (!config[key]) {
if (key in message) {
config[key] = message[key];
}
}
});

let count = 0;
Object.keys(this.ccu.metadata.devices).forEach(iface => {
if (this.iface && iface !== this.iface) {
if (config.iface && iface !== config.iface) {
return;
}

Expand All @@ -82,115 +93,115 @@ module.exports = function (RED) {

if (!this.whitelist.has(address)) {
const device = this.ccu.metadata.devices[iface][channel.PARENT];
if (this.device) {
if (this.deviceRx === 'str' && this.device !== channel.PARENT) {
if (config.device) {
if (config.deviceRx === 'str' && config.device !== channel.PARENT) {
this.blacklist.add(address);
return;
}

if (this.deviceRx === 're' && !channel.PARENT.match(new RegExp(this.device))) {
if (config.deviceRx === 're' && !channel.PARENT.match(new RegExp(config.device))) {
this.blacklist.add(address);
return;
}
}

if (this.deviceType) {
if (this.deviceTypeRx === 'str' && this.deviceType !== device.TYPE) {
if (config.deviceType) {
if (config.deviceTypeRx === 'str' && config.deviceType !== device.TYPE) {
this.blacklist.add(address);
return;
}

if (this.deviceTypeRx === 're' && !device.TYPE.match(new RegExp(this.deviceType))) {
if (config.deviceTypeRx === 're' && !device.TYPE.match(new RegExp(config.deviceType))) {
this.blacklist.add(address);
return;
}
}

if (this.deviceName) {
if (config.deviceName) {
if (!this.ccu.channelNames[address]) {
this.blacklist.add(address);
return;
}

if (this.deviceNameRx === 'str' && this.ccu.channelNames[channel.PARENT] !== this.deviceName) {
if (config.deviceNameRx === 'str' && this.ccu.channelNames[channel.PARENT] !== config.deviceName) {
this.blacklist.add(address);
return;
}

if (this.deviceNameRx === 're' && !this.ccu.channelNames[channel.PARENT].match(new RegExp(this.deviceName))) {
if (config.deviceNameRx === 're' && !this.ccu.channelNames[channel.PARENT].match(new RegExp(config.deviceName))) {
this.blacklist.add(address);
return;
}
}

if (this.channel) {
if (this.channelRx === 'str' && this.channel !== address) {
if (config.channel) {
if (config.channelRx === 'str' && config.channel !== address) {
this.blacklist.add(address);
return;
}

if (this.channelRx === 're' && !address.match(new RegExp(this.channel))) {
if (config.channelRx === 're' && !address.match(new RegExp(config.channel))) {
this.blacklist.add(address);
return;
}
}

if (this.channelType) {
if (this.channelTypeRx === 'str' && this.channelType !== channel.TYPE) {
if (config.channelType) {
if (config.channelTypeRx === 'str' && config.channelType !== channel.TYPE) {
this.blacklist.add(address);
return;
}

if (this.channelTypeRx === 're' && !channel.TYPE.match(new RegExp(this.channelType))) {
if (config.channelTypeRx === 're' && !channel.TYPE.match(new RegExp(config.channelType))) {
this.blacklist.add(address);
return;
}
}

if (this.channelIndex) {
if (this.channelIndexRx === 'str' && !address.endsWith(':' + this.channelIndex)) {
if (config.channelIndex) {
if (config.channelIndexRx === 'str' && !address.endsWith(':' + config.channelIndex)) {
this.blacklist.add(address);
return;
}

if (this.channelIndexRx === 're' && !address.split(':')[1].match(new RegExp(String(this.channelIndex)))) {
if (config.channelIndexRx === 're' && !address.split(':')[1].match(new RegExp(String(config.channelIndex)))) {
this.blacklist.add(address);
return;
}
}

if (this.channelName) {
if (config.channelName) {
if (!this.ccu.channelNames[address]) {
this.blacklist.add(address);
return;
}

if (this.channelNameRx === 'str' && this.ccu.channelNames[address] !== this.channelName) {
if (config.channelNameRx === 'str' && this.ccu.channelNames[address] !== config.channelName) {
this.blacklist.add(address);
return;
}

if (this.channelNameRx === 're' && !this.ccu.channelNames[address].match(new RegExp(this.channelName))) {
if (config.channelNameRx === 're' && !this.ccu.channelNames[address].match(new RegExp(config.channelName))) {
this.blacklist.add(address);
return;
}
}

if (this.rooms) {
if (config.rooms) {
if (!this.ccu.channelRooms[address]) {
this.blacklist.add(address);
return;
}

if (this.roomsRx === 'str' && !this.ccu.channelRooms[address].includes(this.rooms)) {
if (config.roomsRx === 'str' && !this.ccu.channelRooms[address].includes(config.rooms)) {
this.blacklist.add(address);
return;
}

if (this.roomsRx === 're') {
if (config.roomsRx === 're') {
let match = false;
this.ccu.channelRooms[address].forEach(room => {
if (room.match(new RegExp(this.rooms))) {
if (room.match(new RegExp(config.rooms))) {
match = true;
}
});
Expand All @@ -201,21 +212,21 @@ module.exports = function (RED) {
}
}

if (this.functions) {
if (config.functions) {
if (!this.ccu.channelFunctions[address]) {
this.blacklist.add(address);
return;
}

if (this.functionsRx === 'str' && !this.ccu.channelFunctions[address].includes(this.functions)) {
if (config.functionsRx === 'str' && !this.ccu.channelFunctions[address].includes(config.functions)) {
this.blacklist.add(address);
return;
}

if (this.functionsRx === 're') {
if (config.functionsRx === 're') {
let match = false;
this.ccu.channelFunctions[address].forEach(func => {
if (func.match(new RegExp(this.functions))) {
if (func.match(new RegExp(config.functions))) {
match = true;
}
});
Expand All @@ -231,21 +242,21 @@ module.exports = function (RED) {

const psKey = this.ccu.paramsetName(iface, channel, 'VALUES');
if (this.ccu.paramsetDescriptions[psKey]) {
const rx = new RegExp(this.datapoint);
const rx = new RegExp(config.datapoint);
Object.keys(this.ccu.paramsetDescriptions[psKey]).forEach(dp => {
if (this.datapointRx === 'str' && dp !== this.datapoint) {
if (config.datapointRx === 'str' && dp !== config.datapoint) {
return;
}

if (this.datapointRx === 're' && !dp.match(rx)) {
if (config.datapointRx === 're' && !dp.match(rx)) {
return;
}

const datapointName = iface + '.' + address + '.' + dp;
const currentValue = this.ccu.values[datapointName] && this.ccu.values[datapointName].value;
count += 1;
if (dp.startsWith('PRESS_') || typeof currentValue === 'undefined' || currentValue !== message.payload) {
this.ccu.setValueQueued(iface, address, dp, message.payload, false, this.force).catch(() => {});
this.ccu.setValueQueued(iface, address, dp, message.payload, false, config.force).catch(() => {});
}
});
}
Expand Down
7 changes: 2 additions & 5 deletions nodes/locales/de-DE/ccu-set-value.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"ccu-get-value": {
"tip": "Tipp: ",
"change": "Nur geänderte Werte ausgeben",
"cache": "Beim Start letzten bekannten Wert ausgeben",
"working": "Während WORKING keine Werte ausgeben",
"ccu-set-value": {
"tip-message": "Alternativ können die hier einzustellenden Werte auch in der Input-Nachricht festgelegt werden, z.B.:"
}
}
5 changes: 5 additions & 0 deletions nodes/locales/en-US/ccu-set-value.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"ccu-set-value": {
"tip-message": "Alternatively, the settings can also be defined in the input message, e.g:"
}
}

0 comments on commit 4d51afb

Please sign in to comment.