Skip to content

Commit

Permalink
* add message override
Browse files Browse the repository at this point in the history
* finish readme
  • Loading branch information
konne committed Dec 3, 2020
1 parent 72b9f25 commit 2c9faa2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 33 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ Just add the connection settings and select what type of request you want to sen
You can also override the configuration settings with properties that are injected
into the incomig message.

property | type | example
---------|------|--------

property | type | example
------------|-----------------|--------
requesttype | GET / SET / INF | GET
parameters | [] | [700,710] (fetched in GET the parameter 700 & 710)
value | number | 22.0 (only valid for requesttype SET / INF)

## GET

Expand Down
23 changes: 0 additions & 23 deletions example.json

This file was deleted.

25 changes: 18 additions & 7 deletions src/bsb-lan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,33 @@ export = function (RED: NodeAPI) {
let node = this;
let device = RED.nodes.getNode(config.device) as BSBLanDeviceNode;

this.on('input', function (msg: NodeMessageInFlow & {}) {
this.on('input', function (msg: NodeMessageInFlow & any) {

let action: Promise<any>;

switch (config.requesttype) {
let cfg = { ...config};

if (msg?.requesttype == 'GET' || msg?.requesttype == 'SET' || msg?.requesttype == 'INF')
cfg.requesttype= msg.requesttype;

if (msg?.parameters?.length > 0)
cfg.parameters= msg.parameters;

if (msg.value != undefined)
cfg.value = msg.value;

switch (cfg.requesttype) {
case "GET":
action = device.get('JQ=' + config.parameters.join(','));
action = device.get('JQ=' + cfg.parameters.join(','));
break;
case "SET":
case "INF":
if (config.parameters.length == 1) {
if (cfg.parameters.length == 1) {
action = device.post('JS',
{
"Parameter": config.parameters[0],
"Value": config.value,
"Type": config.requesttype == "INF" ? "0" : "1" // "Type" (0 = INF, 1 = SET)
"Parameter": cfg.parameters[0],
"Value": cfg.value,
"Type": cfg.requesttype == "INF" ? "0" : "1" // "Type" (0 = INF, 1 = SET)
}
);
}
Expand Down

0 comments on commit 2c9faa2

Please sign in to comment.