Skip to content

Commit 1eb7ac0

Browse files
authored
Merge pull request #179 from rdmtc/dev
#### 1.1.6: BugFix - general - reworked JSONATA (preparation is now done on node creation)
2 parents c6885ad + 71c785f commit 1eb7ac0

File tree

9 files changed

+136
-82
lines changed

9 files changed

+136
-82
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# node-red-contrib-sun-position
22

3+
#### 1.1.6: BugFix
4+
5+
- general
6+
- reworked JSONATA (preparation is now done on node creation)
7+
38
#### 1.1.5: BugFix
49

510
- general

nodes/blind-control.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,16 @@ module.exports = function (RED) {
11591159
blindPos: getBlindPosFromTI(node, undefined, config.oversteer3BlindPosType, config.oversteer3BlindPos, node.blindData.levelTop)
11601160
});
11611161
}
1162+
node.oversteerData.forEach( (val, _index) => {
1163+
if (node.positionConfig && val.operand.type === 'jsonata') {
1164+
try {
1165+
val.operand.expr = node.positionConfig.getJSONataExpression(node, val.operand.value);
1166+
} catch (err) {
1167+
node.error(RED._('node-red-contrib-sun-position/position-config:errors.invalid-expr', { error:err.message }));
1168+
val.operand.expr = null;
1169+
}
1170+
}
1171+
});
11621172
}
11631173

11641174
node.rules = {

nodes/locales/en-US/position-config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,8 @@
312312
"unknownCompareOperator": "error, the used compare operator \"__operator__\" is unknown! (\"__opTypeA__.__opValueA__\" compare to \"__opTypeB__.__opValueB__\")",
313313
"notEvaluableProperty":"Error: could not evaluate __type__.__value__!",
314314
"notEvaluablePropertyAdd":"Error \"__err__\", could not evaluate __type__.__value__",
315-
"invalidParameter":"Parameter \"__param__\" is invalid \"__type__\" (using __newValue__)"
315+
"invalidParameter":"Parameter \"__param__\" is invalid \"__type__\" (using __newValue__)",
316+
"invalid-expr": "Invalid JSONata expression: __error__"
316317
},
317318
"position-config": {
318319
"label": {

nodes/time-comp.js

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,41 @@ module.exports = function (RED) {
1717
// Retrieve the config node
1818
this.positionConfig = RED.nodes.getNode(config.positionConfig);
1919
// this.debug('initialize time Node ' + util.inspect(config, { colors: true, compact: 10, breakLength: Infinity }));
20+
this.input = {
21+
type: config.inputType,
22+
value: config.input,
23+
format: config.inputFormat,
24+
offsetType: config.inputOffsetType,
25+
offset: config.inputOffset,
26+
multiplier: config.inputOffsetMultiplier
27+
};
28+
29+
this.result1 = {
30+
type : config.result1Type,
31+
value : config.result1,
32+
format : config.result1Format
33+
};
34+
35+
this.result1Value = {
36+
type: config.result1ValueType,
37+
value: config.result1Value,
38+
format: config.result1Format,
39+
offsetType: config.result1OffsetType,
40+
offset: config.result1Offset,
41+
multiplier: config.result1Multiplier,
42+
next: true
43+
};
44+
if (this.positionConfig && this.result1Value.type === 'jsonata') {
45+
try {
46+
this.result1Value.expr = this.positionConfig.getJSONataExpression(this, this.result1Value.value);
47+
} catch (err) {
48+
this.error(RED._('node-red-contrib-sun-position/position-config:errors.invalid-expr', { error:err.message }));
49+
this.result1Value.expr = null;
50+
}
51+
}
52+
53+
this.rules = config.rules;
54+
this.checkall = config.checkall;
2055
const node = this;
2156

2257
this.on('input', (msg, send, done) => {
@@ -26,8 +61,8 @@ module.exports = function (RED) {
2661

2762
if (node.positionConfig === null ||
2863
typeof node.positionConfig === 'undefined' ||
29-
config.inputType === null ||
30-
typeof config.inputType === 'undefined') {
64+
node.input.type === null ||
65+
typeof node.input.type === 'undefined') {
3166
node.status({
3267
fill: 'red',
3368
shape: 'ring',
@@ -37,49 +72,33 @@ module.exports = function (RED) {
3772
}
3873

3974
try {
40-
// const inputData = node.positionConfig.getDateFromProp(node, msg, config.inputType, config.input, config.inputFormat, config.inputOffset, config.inputOffsetType, config.inputOffsetMultiplier);
41-
const inputData = node.positionConfig.getTimeProp(node, msg, {
42-
type: config.inputType,
43-
value: config.input,
44-
format: config.inputFormat,
45-
offsetType: config.inputOffsetType,
46-
offset: config.inputOffset,
47-
multiplier: config.inputOffsetMultiplier
48-
});
75+
// const inputData = node.positionConfig.getDateFromProp(node, msg, node.input.type, node.input.value);
76+
const inputData = node.positionConfig.getTimeProp(node, msg, node.input);
4977
if (inputData.error) {
5078
throw new Error(inputData.error);
5179
}
5280

53-
if (config.result1Type !== 'none') {
81+
if (node.result1.type !== 'none') {
5482
let resultObj = null;
55-
if (config.result1ValueType === 'input') {
56-
resultObj = hlp.getFormattedDateOut(inputData.value, config.result1Format);
83+
if (node.result1Value.type === 'input') {
84+
resultObj = hlp.getFormattedDateOut(inputData.value, node.result1.format);
5785
} else {
58-
resultObj = node.positionConfig.getOutDataProp(node, msg, {
59-
type: config.result1ValueType,
60-
value: config.result1Value,
61-
format: config.result1Format,
62-
offsetType: config.result1OffsetType,
63-
offset: config.result1Offset,
64-
multiplier: config.result1Multiplier,
65-
next: true
66-
});
86+
resultObj = node.positionConfig.getOutDataProp(node, msg, node.result1Value);
6787
}
6888

6989
if (resultObj === null || typeof resultObj === 'undefined') {
70-
throw new Error('could not evaluate ' + config.result1ValueType + '.' + config.result1Value);
90+
throw new Error('could not evaluate ' + node.result1Value.type + '.' + node.result1Value.value);
7191
} else if (resultObj.error) {
7292
node.error('error on getting result: ' + resultObj.error);
7393
} else {
74-
node.positionConfig.setMessageProp(this, msg, config.result1Type, config.result1, resultObj);
94+
node.positionConfig.setMessageProp(this, msg, node.result1.type, node.result1.value, resultObj);
7595
}
7696
}
7797

7898
const resObj = [];
79-
const rules = config.rules;
80-
const rulesLength = rules.length;
99+
const rulesLength = node.rules.length;
81100
for (let i = 0; i < rulesLength; ++i) {
82-
const rule = rules[i];
101+
const rule = node.rules[i];
83102
let operatorValid = true;
84103
if (rule.propertyType !== 'none') {
85104
const res = RED.util.evaluateNodeProperty(rule.propertyValue, rule.propertyType, node, msg);
@@ -223,7 +242,7 @@ module.exports = function (RED) {
223242
if (result) {
224243
resObj.push(msg);
225244
node.debug(i + ' result=' + util.inspect(result, { colors: true, compact: 10, breakLength: Infinity }));
226-
if (config.checkall != 'true') { // eslint-disable-line eqeqeq
245+
if (node.checkall != 'true') { // eslint-disable-line eqeqeq
227246
node.debug(i + ' end cause checkall');
228247
break;
229248
}

nodes/time-inject.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ module.exports = function (RED) {
9393

9494
if (this.positionConfig && this.property.type === 'jsonata') {
9595
try {
96-
this.property.expr = this.positionConfig.getJSONataExpression(this.property.value, node);
96+
this.property.expr = this.positionConfig.getJSONataExpression(this, this.property.value);
9797
} catch (err) {
98-
this.error(RED._('inject.errors.invalid-expr', { error:err.message }));
98+
this.error(RED._('node-red-contrib-sun-position/position-config:errors.invalid-expr', { error:err.message }));
9999
this.property.expr = null;
100100
}
101101
}
@@ -302,9 +302,9 @@ module.exports = function (RED) {
302302

303303
if (this.positionConfig && propNew.type === 'jsonata') {
304304
try {
305-
propNew.expr = this.positionConfig.getJSONataExpression(propNew.value, node);
305+
propNew.expr = this.positionConfig.getJSONataExpression(this, propNew.value);
306306
} catch (err) {
307-
this.error(RED._('inject.errors.invalid-expr', { error:err.message }));
307+
this.error(RED._('node-red-contrib-sun-position/position-config:errors.invalid-expr', { error:err.message }));
308308
propNew.expr = null;
309309
}
310310
}

nodes/time-span.js

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,23 @@ module.exports = function (RED) {
267267
RED.nodes.createNode(this, config);
268268
// Retrieve the config node
269269
this.positionConfig = RED.nodes.getNode(config.positionConfig);
270+
this.result1Value = {
271+
type: config.result1ValueType,
272+
value: config.result1Value,
273+
format: config.result1Format,
274+
offsetType: config.result1OffsetType,
275+
offset: config.result1Offset,
276+
multiplier: config.result1Multiplier,
277+
next: true
278+
};
279+
if (this.positionConfig && this.result1Value.type === 'jsonata') {
280+
try {
281+
this.result1Value.expr = this.positionConfig.getJSONataExpression(this, this.result1Value.value);
282+
} catch (err) {
283+
this.error(RED._('node-red-contrib-sun-position/position-config:errors.invalid-expr', { error:err.message }));
284+
this.result1Value.expr = null;
285+
}
286+
}
270287
const node = this;
271288

272289
this.on('input', (msg, send, done) => {
@@ -331,26 +348,18 @@ module.exports = function (RED) {
331348

332349
if (config.result1Type !== 'none') {
333350
let resultObj = null;
334-
if (config.result1ValueType === 'timespan') {
351+
if (node.result1Value.type === 'timespan') {
335352
resultObj = getFormattedTimeSpanOut(node, operand1.value, operand2.value, config.result1TSFormat);
336-
} else if (config.result1ValueType === 'operand1') {
353+
} else if (node.result1Value.type === 'operand1') {
337354
resultObj = hlp.getFormattedDateOut(operand1.value, config.result1Format);
338-
} else if (config.result1ValueType === 'operand2') {
355+
} else if (node.result1Value.type === 'operand2') {
339356
resultObj = hlp.getFormattedDateOut(operand2.value, config.result1Format);
340357
} else {
341-
resultObj = node.positionConfig.getOutDataProp(node, msg, {
342-
type: config.result1ValueType,
343-
value: config.result1Value,
344-
format: config.result1Format,
345-
offsetType: config.result1OffsetType,
346-
offset: config.result1Offset,
347-
multiplier: config.result1Multiplier,
348-
next: true
349-
});
358+
resultObj = node.positionConfig.getOutDataProp(node, msg, node.result1Value);
350359
}
351360
// node.debug('resultObj=' + util.inspect(resultObj, { colors: true, compact: 10, breakLength: Infinity }));
352361
if (resultObj === null || typeof resultObj === 'undefined') {
353-
throw new Error('could not evaluate ' + config.result1ValueType + '.' + config.result1Value);
362+
throw new Error('could not evaluate ' + node.result1Value.type + '.' + node.result1Value.value);
354363
} else if (resultObj.error) {
355364
node.error('error on getting result: ' + resultObj.error);
356365
} else {

nodes/within-time-switch.js

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ module.exports = function (RED) {
100100
end: {},
101101
startSuffix: '',
102102
endSuffix: '',
103-
altStartTime: (node.propertyStartType !== 'none') && (msg || (node.propertyStartType !== 'msg')),
104-
altEndTime: (node.propertyEndType !== 'none') && (msg || (node.propertyEndType !== 'msg')),
103+
altStartTime: (node.propertyStart.type !== 'none') && (msg || (node.propertyStart.type !== 'msg')),
104+
altEndTime: (node.propertyEnd.type !== 'none') && (msg || (node.propertyEnd.type !== 'msg')),
105105
valid: false,
106106
warn: ''
107107
};
@@ -158,31 +158,25 @@ module.exports = function (RED) {
158158
result.valid = true;
159159

160160
if (result.altStartTime) {
161-
// node.debug('alternate start times enabled ' + node.propertyStartType + '.' + node.propertyStart);
161+
// node.debug('alternate start times enabled ' + node.propertyStart.type + '.' + node.propertyStart.value);
162162
try {
163-
result.altStartTime = node.positionConfig.comparePropValue(node, msg, { type:node.propertyStartType, value:node.propertyStart},
164-
node.propertyStartOperator, {type: node.propertyStartThresholdType, value:node.propertyStartThresholdValue});
163+
result.altStartTime = node.positionConfig.comparePropValue(node, msg, node.propertyStart,
164+
node.propertyStartOperator, node.propertyStartThreshold);
165165
} catch (err) {
166166
result.altStartTime = false;
167-
hlp.handleError(node, RED._('within-time-switch.errors.invalid-propertyStart-type', {
168-
type: node.propertyStartType,
169-
value: node.propertyStart
170-
}), err);
167+
hlp.handleError(node, RED._('within-time-switch.errors.invalid-propertyStart-type', node.propertyStart), err);
171168
node.log(util.inspect(err, Object.getOwnPropertyNames(err)));
172169
}
173170
}
174171

175172
if (result.altEndTime) {
176-
// node.debug('alternate end times enabled ' + node.propertyEndType + '.' + node.propertyEnd);
173+
// node.debug('alternate end times enabled ' + node.propertyEnd.type + '.' + node.propertyEnd.value);
177174
try {
178-
result.altEndTime = node.positionConfig.comparePropValue(node, msg, { type:node.propertyEndType, value:node.propertyEnd},
179-
node.propertyEndOperator, {type:node.propertyEndThresholdType, value:node.propertyEndThresholdValue});
175+
result.altEndTime = node.positionConfig.comparePropValue(node, msg, node.propertyEnd,
176+
node.propertyEndOperator, node.propertyEndThreshold);
180177
} catch (err) {
181178
result.altEndTime = false;
182-
hlp.handleError(node, RED._('within-time-switch.errors.invalid-propertyEnd-type', {
183-
type: node.propertyEndType,
184-
value: node.propertyEnd
185-
}), err);
179+
hlp.handleError(node, RED._('within-time-switch.errors.invalid-propertyEnd-type', node.propertyEnd), err);
186180
}
187181
}
188182

@@ -243,17 +237,41 @@ module.exports = function (RED) {
243237
this.positionConfig = RED.nodes.getNode(config.positionConfig);
244238
// this.debug('initialize withinTimeSwitchNode ' + util.inspect(config, { colors: true, compact: 10, breakLength: Infinity }));
245239

246-
this.propertyStart = config.propertyStart || '';
247-
this.propertyStartType = config.propertyStartType || 'none';
248240
this.propertyStartOperator = config.propertyStartCompare || 'true';
249-
this.propertyStartThresholdValue = config.propertyStartThreshold;
250-
this.propertyStartThresholdType = config.propertyStartThresholdType;
241+
this.propertyStart = {
242+
type : config.propertyStartType || 'none',
243+
value : config.propertyStart || ''
244+
};
245+
this.propertyStartThreshold = {
246+
type : config.propertyStartThresholdType || 'none',
247+
value : config.propertyStartThreshold || ''
248+
};
249+
if (this.positionConfig && this.propertyStart.type === 'jsonata') {
250+
try {
251+
this.propertyStart.expr = this.positionConfig.getJSONataExpression(this, this.propertyStart.value);
252+
} catch (err) {
253+
this.error(RED._('node-red-contrib-sun-position/position-config:errors.invalid-expr', { error:err.message }));
254+
this.propertyStart.expr = null;
255+
}
256+
}
251257

252-
this.propertyEnd = config.propertyEnd || '';
253-
this.propertyEndType = config.propertyEndType || 'none';
254258
this.propertyEndOperator = config.propertyEndCompare || 'true';
255-
this.propertyEndThresholdValue = config.propertyEndThreshold;
256-
this.propertyEndThresholdType = config.propertyEndThresholdType;
259+
this.propertyEnd = {
260+
type : config.propertyEndType || 'none',
261+
value : config.propertyEnd || ''
262+
};
263+
this.propertyEndThreshold = {
264+
type : config.propertyEndThresholdType || 'none',
265+
value : config.propertyEndThreshold || ''
266+
};
267+
if (this.positionConfig && this.propertyEnd.type === 'jsonata') {
268+
try {
269+
this.propertyEnd.expr = this.positionConfig.getJSONataExpression(this, this.propertyEnd.value);
270+
} catch (err) {
271+
this.error(RED._('node-red-contrib-sun-position/position-config:errors.invalid-expr', { error:err.message }));
272+
this.propertyEnd.expr = null;
273+
}
274+
}
257275

258276
this.timeOnlyEvenDays = config.timeOnlyEvenDays;
259277
this.timeOnlyOddDays = config.timeOnlyOddDays;

package-lock.json

Lines changed: 1 addition & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-contrib-sun-position",
3-
"version": "1.1.5",
3+
"version": "1.1.6",
44
"description": "NodeRED nodes to get sun and moon position",
55
"keywords": [
66
"node-red",
@@ -95,9 +95,7 @@
9595
"eslint-plugin-html": "^6.0.3",
9696
"eslint-plugin-jsdoc": "^30.3.0",
9797
"eslint-plugin-json": "^2.1.2",
98-
"eslint-plugin-node": "^11.1.0",
99-
"minimist": ">=1.2.5",
100-
"yargs-parser": ">=19.0.1"
98+
"eslint-plugin-node": "^11.1.0"
10199
},
102100
"disabledSettings": {
103101
"plugins-disabled": [

0 commit comments

Comments
 (0)