Skip to content

Commit

Permalink
Merge pull request #71 from rdmtc/dev
Browse files Browse the repository at this point in the history
0.5.2: BugFix
  • Loading branch information
Hypnos3 authored Nov 10, 2019
2 parents 7f83348 + 1117a07 commit c9cd9c9
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 47 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# node-red-contrib-sun-position

#### 0.5.1-beta-0: BugFix and Maintenance Release
#### 0.5.2: BugFix

- general
- fix for error on getting tooltip #69

#### 0.5.1: BugFix and Maintenance Release

- general
- fix for week number calculation when in daylight saving #65
Expand Down
22 changes: 14 additions & 8 deletions nodes/blind-control.html
Original file line number Diff line number Diff line change
Expand Up @@ -1599,13 +1599,15 @@
$dialogTimeRegInput.attr('timedata', dialogAddData.timeReg.ts);
_dialogGenHelpText();
}, {
kind: 'getTimeData',
config : $nodeConfig.val(),
type: opType,
value: $dialogTimeRegInput.typedInput('value'),
nodeId: node.id,
kind: 'getTimeData',
config: $nodeConfig.val(),
type: opType,
value: $dialogTimeRegInput.typedInput('value'),
offsetType: $dialogTimeRegOffset.typedInput('type'),
offset: $dialogTimeRegOffset.typedInput('value'),
multiplier: parseInt($dialogTimeRegMultiplier.val())
offset: $dialogTimeRegOffset.typedInput('value'),
multiplier: parseInt($dialogTimeRegMultiplier.val()),
noOffsetError: true
});
$dialogTimeMinInput.change();
$dialogTimeMaxInput.change();
Expand Down Expand Up @@ -1652,13 +1654,15 @@
$dialogTimeMinInput.attr('timedata', dialogAddData.timeMin.ts);
_dialogGenHelpText();
}, {
nodeId: node.id,
kind: 'getTimeData',
config: $nodeConfig.val(),
type: opType,
value: $dialogTimeMinInput.typedInput('value'),
offsetType: $dialogTimeMinOffset.typedInput('type'),
offset: $dialogTimeMinOffset.typedInput('value'),
multiplier: parseInt($dialogTimeMinMultiplier.val())
multiplier: parseInt($dialogTimeMinMultiplier.val()),
noOffsetError: true
});
}
});
Expand Down Expand Up @@ -1704,13 +1708,15 @@
$dialogTimeMaxInput.attr('timedata', dialogAddData.timeMax.ts);
_dialogGenHelpText();
}, {
nodeId: node.id,
kind: 'getTimeData',
config: $nodeConfig.val(),
type: opType,
value: $dialogTimeMaxInput.typedInput('value'),
offsetType: $dialogTimeMaxOffset.typedInput('type'),
offset: $dialogTimeMaxOffset.typedInput('value'),
multiplier: parseInt($dialogTimeMaxMultiplier.val())
multiplier: parseInt($dialogTimeMaxMultiplier.val()),
noOffsetError: true
});
}
});
Expand Down
49 changes: 29 additions & 20 deletions nodes/position-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ module.exports = function (RED) {
* @param {*} [opCallback] - callback function for getting getPropValue
* @returns {number} float property
*/
getFloatProp(_srcNode, msg, type, value, def, opCallback) {
// _srcNode.debug('getFloatProp type='+type+' value='+value);
getFloatProp(_srcNode, msg, type, value, def, opCallback, noError) {
_srcNode.debug('getFloatProp type='+type+' value='+value);
let data; // 'msg', 'flow', 'global', 'num', 'bin', 'env', 'jsonata'
if (type === 'num') {
data = Number(value); // extra conversation to handle empty string as 0
Expand All @@ -404,10 +404,12 @@ module.exports = function (RED) {
data = this.getPropValue(_srcNode, msg, { type, value, callback:opCallback });
}
if (data === null || typeof data === 'undefined') {
if (noError) { return NaN; }
throw new Error(RED._('errors.error', { message: RED._('errors.notEvaluableProperty', {type, value}) }));
}
data = parseFloat(data);
if (isNaN(data)) {
if (noError) { return NaN; }
throw new Error('the value of ' + type + '.' + value + ' is not a valid Number!');
}
return data;
Expand Down Expand Up @@ -440,7 +442,7 @@ module.exports = function (RED) {
let result = null;
if (data.type === null || data.type === 'none' || data.type === '' || (typeof data.type === 'undefined')) {
if (data.value === '' || (typeof data.value === 'undefined')) {
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0);
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0, data.offsetCallback, data.noOffsetError);
result = hlp.addOffset(now, offsetX, data.multiplier);
return hlp.getFormattedDateOut(result, data.format, (this.tzOffset === 0), this.tzOffset);
}
Expand All @@ -451,15 +453,15 @@ module.exports = function (RED) {
}
return Date.now();
} else if (data.type === 'dateSpecific') {
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0);
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0, data.offsetCallback, data.noOffsetError);
result = hlp.addOffset(now, offsetX, data.multiplier);
return hlp.getFormattedDateOut(result, data.format, (this.tzOffset === 0), this.tzOffset);
} else if ((data.type === 'pdsTime') || (data.type === 'pdmTime')) {
if (data.type === 'pdsTime') { // sun
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0);
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0, data.offsetCallback, data.noOffsetError);
result = this.getSunTimeByName(now, data.value, offsetX, data.multiplier, data.next, data.days);
} else if (data.type === 'pdmTime') { // moon
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0);
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0, data.offsetCallback, data.noOffsetError);
result = this.getMoonTimeByName(now, data.value, offsetX, data.multiplier, data.next, data.days);
}
if (result && result.value && !result.error) {
Expand All @@ -470,14 +472,14 @@ module.exports = function (RED) {
return Object.assign({}, this.getSunTimePrevNext(now));
} else if (data.type === 'entered' || data.type === 'dateEntered') {
result = hlp.getDateOfText(String(data.value), (this.tzOffset === 0), this.tzOffset);
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0);
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0, data.offsetCallback, data.noOffsetError);
result = hlp.normalizeDate(result, offsetX, data.multiplier, data.next, data.days);
return hlp.getFormattedDateOut(result, data.format, (this.tzOffset === 0), this.tzOffset);
} else if (data.type === 'dayOfMonth') {
result = new Date();
result = hlp.getSpecialDayOfMonth(result.getFullYear(),result.getMonth(), data.value);
if (result !== null && typeof result !== 'undefined') {
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0);
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0, data.offsetCallback, data.noOffsetError);
result = hlp.normalizeDate(result, offsetX, data.multiplier, data.next, data.days);
return hlp.getFormattedDateOut(result, data.format, (this.tzOffset === 0), this.tzOffset);
}
Expand Down Expand Up @@ -515,7 +517,7 @@ module.exports = function (RED) {
* @returns {timePropResultType} value of the type input
*/
getTimeProp(_srcNode, msg, data) {
// _srcNode.debug(`getTimeProp data=${util.inspect(data, { colors: true, compact: 10, breakLength: Infinity })} tzOffset=${this.tzOffset}`);
_srcNode.debug(`getTimeProp data=${util.inspect(data, { colors: true, compact: 10, breakLength: Infinity })} tzOffset=${this.tzOffset}`);
let result = {
value: null,
error: null,
Expand All @@ -535,44 +537,44 @@ module.exports = function (RED) {
}
result.fix = true;
} else if (data.type === 'dateSpecific') {
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0);
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0, data.offsetCallback, data.noOffsetError);
result.value = hlp.normalizeDate(now, offsetX, data.multiplier, data.next, data.days);
if (this.tzOffset) {
result.value = hlp.convertDateTimeZone(result.value);
}
result.fix = true;
} else if (data.type === 'dayOfMonth') {
result.value = hlp.getSpecialDayOfMonth(now.getFullYear(), now.getMonth(), data.value);
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0);
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0, data.offsetCallback, data.noOffsetError);
result.value = hlp.normalizeDate(result.value, offsetX, data.multiplier, data.next, data.days);
if (this.tzOffset) {
result.value = hlp.convertDateTimeZone(result.value);
}
} else if (data.type === 'entered') {
result.value = hlp.getTimeOfText(String(data.value), now, (this.tzOffset === 0), this.tzOffset);
if (result.value !== null) {
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0);
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0, data.offsetCallback, data.noOffsetError);
result.value = hlp.normalizeDate(result.value, offsetX, data.multiplier, data.next, data.days);
}
result.fix = true;
} else if (data.type === 'dateEntered') {
result.value = hlp.getDateOfText(String(data.value), (this.tzOffset === 0), this.tzOffset);
if (result.value !== null) {
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0);
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0, data.offsetCallback, data.noOffsetError);
result.value = hlp.normalizeDate(result.value, offsetX, data.multiplier, data.next, data.days);
}
result.fix = true;
} else if (data.type === 'pdsTime') {
// sun
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0);
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0, data.offsetCallback, data.noOffsetError);
result = this.getSunTimeByName(now, data.value, offsetX, data.multiplier, data.next, data.days);
if (this.tzOffset) {
result.value = hlp.convertDateTimeZone(result.value, this.tzOffset);
}
result.fix = true;
} else if (data.type === 'pdmTime') {
// moon
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0);
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0, data.offsetCallback, data.noOffsetError);
result = this.getMoonTimeByName(now, data.value, offsetX, data.multiplier, data.next, data.days);
if (this.tzOffset) {
result.value = hlp.convertDateTimeZone(result.value, this.tzOffset);
Expand All @@ -587,7 +589,7 @@ module.exports = function (RED) {
} else {
result.value = hlp.getDateOfText(data.value, (this.tzOffset === 0), this.tzOffset);
}
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0);
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0, data.offsetCallback, data.noOffsetError);
result.value = hlp.normalizeDate(result.value, offsetX, data.multiplier, data.next, data.days);
if (this.tzOffset) {
result.value = hlp.convertDateTimeZone(result.value, this.tzOffset);
Expand All @@ -602,7 +604,7 @@ module.exports = function (RED) {
} else {
result.value = hlp.getDateOfText(res, (this.tzOffset === 0), this.tzOffset);
}
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0);
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0, data.offsetCallback, data.noOffsetError);
result.value = hlp.normalizeDate(result.value, offsetX, data.multiplier, data.next, data.days);
if (this.tzOffset) {
result.value = hlp.convertDateTimeZone(result.value, this.tzOffset);
Expand Down Expand Up @@ -1095,7 +1097,7 @@ module.exports = function (RED) {
});

RED.httpAdmin.get('/sun-position/data', RED.auth.needsPermission('sun-position.read'), (req, res) => {
// console.log('RED.httpAdmin.get - result for getTimeData', req.query.config);
// console.log('RED.httpAdmin.get', req.query.config);
if (req.query.config && req.query.config !== '_ADD_') {
const posConfig = RED.nodes.getNode(req.query.config);
if (!posConfig) {
Expand All @@ -1104,11 +1106,18 @@ module.exports = function (RED) {
}));
return;
}
let scrNode;
if (req.query.nodeId) {
scrNode = RED.nodes.getNode(req.query.nodeId);
}
if (!scrNode) {
scrNode = posConfig;
}
let obj = {};
switch (req.query.kind) {
case 'getTimeData': {
try {
obj = posConfig.getTimeProp(posConfig, undefined, req.query); // req.query.type, req.query.value, req.query.offsetType, req.query.offset, req.query.multiplier, req.query.next, req.query.days);
obj = posConfig.getTimeProp(scrNode, undefined, req.query); // req.query.type, req.query.value, req.query.offsetType, req.query.offset, req.query.multiplier, req.query.next, req.query.days);
} catch(err) {
obj.value = NaN;
obj.error = err.message;
Expand All @@ -1119,7 +1128,7 @@ module.exports = function (RED) {
}
case 'getOutDataData': {
try {
obj = posConfig.getOutDataProp(posConfig, undefined, req.query); // req.query.type, req.query.value, req.query.format, req.query.offset, req.query.offsetType, req.query.multiplier, req.query.next, req.query.days);
obj = posConfig.getOutDataProp(scrNode, undefined, req.query); // req.query.type, req.query.value, req.query.format, req.query.offset, req.query.offsetType, req.query.multiplier, req.query.next, req.query.days);
} catch(err) {
obj.value = NaN;
obj.error = err.message;
Expand Down
Loading

0 comments on commit c9cd9c9

Please sign in to comment.