Skip to content

Commit

Permalink
allow some options to be set via msg/context/env (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
hobbyquaker committed May 11, 2019
1 parent 0a5f42e commit ae139b4
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 72 deletions.
51 changes: 46 additions & 5 deletions nodes/ccu-signal.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@
chime: {value: ''},
length: {value: 108000},
repeat: {value: 1},
repeatType: {value: 'num'},
volume: {value: 100},
volumeType: {value: 'num'},
line1: {value: ''},
icon1: {value: ''},
line2: {value: ''},
Expand All @@ -82,13 +84,16 @@
acousticAlarmSelection: {value: 'DISABLE_ACOUSTIC_SIGNAL'},
durationUnit: {value: 'S'},
durationValue: {value: 0},
durationValueType: {value: 'num'},
rampTimeUnit: {value: 'S'},
rampTimeValue: {value: 0},
rampTimeValueType: {value: 'num'},
repetitions: {value: 0},
dimmerColor: {value: 0},
dimmerLevel: {value: 100},
dimmerList: {value: []},
soundLevel: {value: 50},
soundLevelType: {value: 'num'},
soundList: {value: []},
opticalAlarmSelection: {value: 'DISABLE_OPTICAL_SIGNAL'},
ccuConfig: {value: 'localhost', type: 'ccu-connection', required: true}
Expand All @@ -112,6 +117,36 @@
const $nodeInputIface = $('#node-input-iface');
const $nodeInputName = $('#node-input-name');

$('#node-input-repeat').typedInput({
default: 'num',
types: ['num', 'msg', 'flow', 'global', 'env'],
typeField: '#node-input-repeatType'
});

$('#node-input-volume').typedInput({
default: 'num',
types: ['num', 'msg', 'flow', 'global', 'env'],
typeField: '#node-input-volumeType'
});

$('#node-input-durationValue').typedInput({
default: 'num',
types: ['num', 'msg', 'flow', 'global', 'env'],
typeField: '#node-input-durationValueType'
});

$('#node-input-rampTimeValue').typedInput({
default: 'num',
types: ['num', 'msg', 'flow', 'global', 'env'],
typeField: '#node-input-rampTimeValueType'
});

$('#node-input-soundLevel').typedInput({
default: 'num',
types: ['num', 'msg', 'flow', 'global', 'env'],
typeField: '#node-input-soundLevelType'
});

let data;

let ifacesLoaded = false;
Expand Down Expand Up @@ -433,12 +468,14 @@

<div class="form-row SUBMIT SIGNAL_CHIME">
<label for="node-input-volume"><i class="fa fa-volume-up"></i> Lautstärke</label>
<input type="number" id="node-input-volume" min="0" max="100">
<input type="text" id="node-input-volume">
<input type="hidden" id="node-input-volumeType">
</div>

<div class="form-row SUBMIT SIGNAL_CHIME SIGNAL_LED">
<label for="node-input-repeat"><i class="icon-repeat"></i> Wiederholungen</label>
<input type="number" min="0" max="255" id="node-input-repeat">
<input type="text" id="node-input-repeat">
<input type="hidden" id="node-input-repeatType">
</div>

<div class="form-row SUBMIT SIGNAL_CHIME">
Expand Down Expand Up @@ -524,7 +561,8 @@

<div class="form-row SUBMIT ACOUSTIC_SIGNAL_VIRTUAL_RECEIVER ">
<label for="node-input-soundLevel"><i class=""></i> Lautstärke </label>
<input id="node-input-soundLevel" type="number" min="0" max="100">
<input id="node-input-soundLevel" type="text">
<input id="node-input-soundLevelType" type="hidden">
</div>

<div class="form-row SUBMIT BSL_DIMMER_VIRTUAL_RECEIVER">
Expand All @@ -544,6 +582,7 @@
<div class="form-row SUBMIT DIMMER_VIRTUAL_RECEIVER BSL_DIMMER_VIRTUAL_RECEIVER">
<label for="node-input-dimmerLevel"><i class=""></i> Helligkeit </label>
<input id="node-input-dimmerLevel" type="number" min="0" max="100">
<input id="node-input-dimmerLevelType" type="hidden">
</div>


Expand All @@ -554,7 +593,8 @@
<option value="M">Minuten</option>
<option value="H">Stunden</option>
</select>
<input id="node-input-rampTimeValue" type="number" style="width: 35%">
<input id="node-input-rampTimeValue" type="text" style="width: 35%">
<input id="node-input-rampTimeValueType" type="hidden">
</div>


Expand All @@ -565,7 +605,8 @@
<option value="M">Minuten</option>
<option value="H">Stunden</option>
</select>
<input id="node-input-durationValue" type="number" style="width: 35%">
<input id="node-input-durationValue" type="text" style="width: 35%">
<input id="node-input-durationValueType" type="hidden">
</div>


Expand Down
192 changes: 125 additions & 67 deletions nodes/ccu-signal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ module.exports = function (RED) {
constructor(config) {
RED.nodes.createNode(this, config);

this.config = config;

this.ccu = RED.nodes.getNode(config.ccuConfig);

if (!this.ccu) {
Expand All @@ -17,84 +19,140 @@ module.exports = function (RED) {

this.ccu.register(this);

this.on('input', () => {
let payload;
this.debug(config.channelType);
switch (config.channelType) {
case 'SIGNAL_CHIME':
payload = config.chime;
this.ccu.setValue(config.iface, config.channel, 'SUBMIT', payload);
break;
case 'SIGNAL_LED':
payload = config.led;
this.ccu.setValue(config.iface, config.channel, 'SUBMIT', payload);
break;
case 'ALARM_SWITCH_VIRTUAL_RECEIVER':
this.ccu.methodCall(config.iface, 'putParamset', [config.channel, 'VALUES', {
ACOUSTIC_ALARM_SELECTION: config.acousticAlarmSelection,
DURATION_UNIT: config.durationUnit,
DURATION_VALUE: parseInt(config.durationValue, 10) || 0,
OPTICAL_ALARM_SELECTION: config.opticalAlarmSelection
}]);
break;
case 'DIMMER_VIRTUAL_RECEIVER': {
const params = {
LEVEL: config.dimmerLevel / 100,
RAMP_TIME_UNIT: config.rampTimeUnit,
RAMP_TIME_VALUE: Number(config.rampTimeValue),
DURATION_UNIT: config.durationUnit,
DURATION_VALUE: parseInt(config.durationValue, 10) || 0,
REPETITIONS: Number(config.repetitions),
OUTPUT_SELECT_SIZE: config.dimmerList.length
};
config.dimmerList.forEach((item, i) => {
const index = i + 1;
params['COLOR_LIST_' + index] = Number(item.color);
params['ON_TIME_LIST_' + index] = Number(item.ontime);
});
this.ccu.methodCall(config.iface, 'putParamset', [config.channel, 'VALUES', params]);
break;
}
this.values = {};

case 'BSL_DIMMER_VIRTUAL_RECEIVER': {
this.ccu.methodCall(config.iface, 'putParamset', [config.channel, 'VALUES', {
LEVEL: config.dimmerLevel / 100,
RAMP_TIME_UNIT: config.rampTimeUnit,
RAMP_TIME_VALUE: Number(config.rampTimeValue),
DURATION_UNIT: config.durationUnit,
DURATION_VALUE: parseInt(config.durationValue, 10) || 0,
COLOR: Number(config.dimmerColor)
}]);
this.on('input', msg => {
const values = {};

this.getValue(values, 'rampTimeValue', msg)
.then(() => this.getValue(values, 'durationValue', msg))
.then(() => this.getValue(values, 'repeat', msg))
.then(() => this.getValue(values, 'volume', msg))
.then(() => this.getValue(values, 'soundLevel', msg))
.catch(err => {
this.error(err.message);
})
.then(() => {
this.sendCommand(Object.assign({}, this.config, values));
});
});
}

sendCommand(config) {
let payload;
this.debug(config.channelType);

switch (config.channelType) {
case 'SIGNAL_CHIME':
payload = config.chime;
this.ccu.setValue(config.iface, config.channel, 'SUBMIT', payload);
break;
case 'SIGNAL_LED':
payload = config.led;
this.ccu.setValue(config.iface, config.channel, 'SUBMIT', payload);
break;
case 'ALARM_SWITCH_VIRTUAL_RECEIVER':
this.ccu.methodCall(config.iface, 'putParamset', [config.channel, 'VALUES', {
ACOUSTIC_ALARM_SELECTION: config.acousticAlarmSelection,
DURATION_UNIT: config.durationUnit,
DURATION_VALUE: parseInt(config.durationValue, 10) || 0,
OPTICAL_ALARM_SELECTION: config.opticalAlarmSelection
}]);
break;
case 'DIMMER_VIRTUAL_RECEIVER': {
const params = {
LEVEL: config.dimmerLevel / 100,
RAMP_TIME_UNIT: config.rampTimeUnit,
RAMP_TIME_VALUE: Number(config.rampTimeValue),
DURATION_UNIT: config.durationUnit,
DURATION_VALUE: parseInt(config.durationValue, 10) || 0,
REPETITIONS: Number(config.repetitions),
OUTPUT_SELECT_SIZE: config.dimmerList.length
};
config.dimmerList.forEach((item, i) => {
const index = i + 1;
params['COLOR_LIST_' + index] = Number(item.color);
params['ON_TIME_LIST_' + index] = Number(item.ontime);
});
this.ccu.methodCall(config.iface, 'putParamset', [config.channel, 'VALUES', params]);
break;
}

case 'BSL_DIMMER_VIRTUAL_RECEIVER': {
this.ccu.methodCall(config.iface, 'putParamset', [config.channel, 'VALUES', {
LEVEL: config.dimmerLevel / 100,
RAMP_TIME_UNIT: config.rampTimeUnit,
RAMP_TIME_VALUE: Number(config.rampTimeValue),
DURATION_UNIT: config.durationUnit,
DURATION_VALUE: parseInt(config.durationValue, 10) || 0,
COLOR: Number(config.dimmerColor)
}]);
break;
}

case 'ACOUSTIC_SIGNAL_VIRTUAL_RECEIVER': {
const params = {
LEVEL: config.soundLevel / 100,
RAMP_TIME_UNIT: config.rampTimeUnit,
RAMP_TIME_VALUE: Number(config.rampTimeValue),
DURATION_UNIT: config.durationUnit,
DURATION_VALUE: parseInt(config.durationValue, 10) || 0,
REPETITIONS: Number(config.repetitions),
OUTPUT_SELECT_SIZE: config.soundList.length
};
config.soundList.forEach((item, i) => {
const index = i + 1;
params['SOUNDFILE_LIST_' + index] = Number(item.sound);
});
this.ccu.methodCall(config.iface, 'putParamset', [config.channel, 'VALUES', params]);
break;
}

default:
console.error('channelType', config.channelType, 'unknown');
}
}

setStatus(data) {
statusHelper(this, data);
}

getValue(values, name, msg) {
return new Promise((resolve, reject) => {
const type = this.config[name + 'Type'];
const val = this.config[name];

switch (type) {
case 'msg':
values[name] = RED.util.getMessageProperty(msg, val);
resolve();
break;
}

case 'ACOUSTIC_SIGNAL_VIRTUAL_RECEIVER': {
const params = {
LEVEL: config.soundLevel / 100,
RAMP_TIME_UNIT: config.rampTimeUnit,
RAMP_TIME_VALUE: Number(config.rampTimeValue),
DURATION_UNIT: config.durationUnit,
DURATION_VALUE: parseInt(config.durationValue, 10) || 0,
REPETITIONS: Number(config.repetitions),
OUTPUT_SELECT_SIZE: config.soundList.length
};
config.soundList.forEach((item, i) => {
const index = i + 1;
params['SOUNDFILE_LIST_' + index] = Number(item.sound);
case 'flow':
case 'global': {
const contextKey = RED.util.parseContextStore(val);
this.context()[type].get(contextKey.key, contextKey.store, (err, res) => {
if (err) {
reject(err);
} else {
values[name] = res;
resolve();
}
});
this.ccu.methodCall(config.iface, 'putParamset', [config.channel, 'VALUES', params]);
break;
}

case 'env':
values[name] = RED.util.evaluateNodeProperty(val, 'env', this);
resolve();
break;

default:
console.error('channelType', config.channelType, 'unknown');
values[name] = val;
resolve();
}
});
}

setStatus(data) {
statusHelper(this, data);
}
}

RED.nodes.registerType('ccu-signal', CcuSignal);
Expand Down

0 comments on commit ae139b4

Please sign in to comment.