Socket
Socket
Sign inDemoInstall

node-red-contrib-sun-position

Package Overview
Dependencies
1
Maintainers
1
Versions
136
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.14-beta.7 to 0.1.16

images/time-inject-settings-addProp1.png

4

nodes/lib/suncalc.js

@@ -210,2 +210,4 @@ /*

};
result.solarNoon.ts = result.solarNoon.value.getTime();
result.nadir.ts = result.nadir.value.getTime();
for (let i = 0, len = sunTimes.length; i < len; i += 1) {

@@ -229,2 +231,4 @@ let time = sunTimes[i];

};
result[time[2]].ts = result[time[2]].value.getTime();
result[time[1]].ts = result[time[1]].value.getTime();
}

@@ -231,0 +235,0 @@ // for backward compatibilit

190

nodes/locales/en-US/time-inject.json
{
"time-inject": {
"label": {
"time-inject": "time-inject",
"inject": "inject",
"position": "Position",
"name": "Name",
"property": "Property",
"time": "Time",
"offset": "Offset",
"timeAlt": "Alternate time",
"timeAltoffset": "Offset",
"recalcTime": "Reclac.",
"payload": "Payload",
"topic": "Topic",
"seconds": "seconds",
"minutes": "minutes",
"hours": "hours",
"on": "on",
"none": "none",
"stopped": "stopped",
"timestamp": "timestamp",
"binary": "binary",
"json": "json",
"jsonata": "json expr.",
"blank": "\"\"",
"5minutes": "every 5 minutes",
"10minutes": "every 10 minutes",
"15minutes": "every 15 minutes",
"30minutes": "every 30 minutes",
"1hour": "every hour",
"2hours": "every 2 hour",
"4hours": "every 4 hour",
"6hours": "every 6 hour",
"12hours": "every 12 hour",
"24hours": "every 24 hour",
"once": "additional",
"onstart": "Inject on start ",
"onceDelay": "seconds",
"success": "Successfully injected: __label__"
},
"days": [
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday"
],
"placeholder": {
"position": "Position",
"name": "Name",
"topic": "Name",
"property": "Property",
"payloadStart": "",
"payloadEnd": "",
"startTime": "7:40",
"startOffset": "0",
"time": "18:15",
"Offset": "0",
"timeAlt": "18:15",
"timeAltOffset": "0"
},
"tips": {
"config": "If time is set to 'not used' the inject node can only used manually or once!",
"addTimes": "Here can be defined alternate time. If the given property is true the alternate time will be used instead the normal time. This can be used to have different time for holidays or other special days.",
"recalc": "If the timestamp is given through a flow or global context, changes to these contexts only lead to a change of the planned emit time if a recalculation is done."
},
"errors": {
"error": "<strong>Error</strong>: __message__",
"error-text": "Exception occured on time-inject",
"error-title": "internal error",
"unexpected": "unexpected error (__status__) __message__",
"invalid-property-type": "Invalid Property Type: __type__",
"invalid-json": "Invalid 'to' JSON property",
"invalid-jsonata-expr": "Invalid JSONata expression: __error__",
"not-deployed": "node not deployed",
"no-response": "no response from server",
"failed": "inject failed, see log for details",
"failed2": "Inject failed: __error__",
"toolong": "Interval too large"
}
}
"time-inject": {
"label": {
"time-inject": "time-inject",
"inject": "inject",
"position": "Position",
"name": "Name",
"property": "Property",
"time": "Time",
"offset": "Offset",
"timeAlt": "Alternate time",
"timeAltoffset": "Offset",
"addPayload1": "set",
"addPayload2": "(2) set",
"addPayload3": "(3) set",
"addPayload1Value": "value",
"addPayload2Value": "value",
"addPayload3Value": "value",
"addPayload1Format": "time format",
"addPayload2Format": "time format",
"addPayload3Format": "time format",
"recalcTime": "Reclac.",
"payload": "Payload",
"topic": "Topic",
"seconds": "seconds",
"minutes": "minutes",
"hours": "hours",
"timeformat": "time format",
"timeformat_UNIX": "number - milliseconds UNIX timestamp",
"timeformat_ECMA262": "string - ECMA-262",
"timeformat_local": "string - local date and time",
"timeformat_localTime": "string - local time",
"timeformat_UTC": "string - UTC date and time",
"timeformat_ISO": "string - ISO date and time",
"timeformat_ms": "number - milliseconds since emit",
"timeformat_sec": "number - seconds since emit",
"timeformat_min": "number - minutes since emit",
"timeformat_hour": "number - hour since emit",
"timeformat_YYYYMMDDHHMMSS" : "string - YYYYMMDDHHMMSS",
"timeformat_YYYYMMDD_HHMMSS" : "string - YYYYMMDD.HHMMSS",
"timeformat_obj": "as object",
"on": "on",
"none": "none",
"stopped": "stopped",
"timestamp": "timestamp",
"binary": "binary",
"json": "json",
"jsonata": "json expr.",
"blank": "\"\"",
"5minutes": "every 5 minutes",
"10minutes": "every 10 minutes",
"15minutes": "every 15 minutes",
"30minutes": "every 30 minutes",
"1hour": "every hour",
"2hours": "every 2 hour",
"4hours": "every 4 hour",
"6hours": "every 6 hour",
"12hours": "every 12 hour",
"24hours": "every 24 hour",
"once": "additional",
"onstart": "Inject on start ",
"onceDelay": "seconds",
"success": "Successfully injected: __label__"
},
"days": [
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday"
],
"placeholder": {
"position": "Position",
"name": "Name",
"topic": "Name",
"property": "Property",
"payloadStart": "",
"payloadEnd": "",
"startTime": "7:40",
"startOffset": "0",
"time": "18:15",
"offset": "0",
"timeAlt": "18:15",
"timeAltOffset": "0"
},
"tips": {
"config": "If time is set to 'not used' the inject node can only used manually or once!",
"addTimes": "Here can be defined alternate time. If the given property is true the alternate time will be used instead the normal time. This can be used to have different time for holidays or other special days.",
"recalc": "If the timestamp is given through a flow or global context, changes to these contexts only lead to a change of the planned emit time if a recalculation is done.",
"addPayload" : "With the additional message properties you can send the message with define up to 3 additional properties with enhanced settings. Especial there can be defined timestamps in relation to the message send timestamp."
},
"errors": {
"error": "<strong>Error</strong>: __message__",
"error-text": "Exception occured on time-inject",
"error-title": "internal error",
"unexpected": "unexpected error (__status__) __message__",
"invalid-property-type": "Invalid Property Type: __type__",
"invalid-json": "Invalid 'to' JSON property",
"invalid-jsonata-expr": "Invalid JSONata expression: __error__",
"not-deployed": "node not deployed",
"no-response": "no response from server",
"failed": "inject failed, see log for details",
"failed2": "Inject failed: __error__",
"toolong": "Interval too large"
}
}
}

@@ -179,3 +179,3 @@ /********************************************

} else if (vType === 'date') {
result.value = now;
result.value = hlp.calcTimeValue(now, offset);
result.fix = true;

@@ -365,3 +365,3 @@ } else if (vType === 'entered') {

return {
date: dateb,
calcDate: dateb,
dayId: day_id

@@ -403,3 +403,3 @@ }

return {
date: dateb,
calcDate: dateb,
dayId: day_id

@@ -406,0 +406,0 @@ }

/********************************************
* within-time-switch:
* time-inject:
*********************************************/

@@ -11,5 +11,119 @@ "use strict";

module.exports = function (RED) {
module.exports = function(RED) {
"use strict";
function getforamtDateCmp(date) {
function pad2(n) { // always returns a string
return (n < 10 ? '0' : '') + n;
}
return Number(date.getFullYear() +
pad2(date.getMonth() + 1) +
pad2(date.getDate()) +
pad2(date.getHours()) +
pad2(date.getMinutes()) +
pad2(date.getSeconds()));
}
function getforamtDateCmp2(date) {
function pad2(n) { // always returns a string
return (n < 10 ? '0' : '') + n;
}
return Number(date.getFullYear() +
pad2(date.getMonth() + 1) +
pad2(date.getDate()) + '.' +
pad2(date.getHours()) +
pad2(date.getMinutes()) +
pad2(date.getSeconds()));
}
function tsGetScheduleTime(time, limit) {
var now = new Date();
var millis = time.getTime() - now.getTime();
if (limit) {
while (millis < limit) {
millis += 86400000; //24h
}
}
return millis;
}
function tsGetPropData(node, msg, type, value, format, offset, days) {
if (type == null || type === "none" || type === "" || (typeof type === 'undefined')) {
if (value === "" || (typeof value === 'undefined')) {
return Date.now();
} else {
return value;
}
} else if (type === "pdsCalcData") {
return node.positionConfig.getSunCalc(msg.ts);
} else if (type === "pdmCalcData") {
return node.positionConfig.getMoonCalc(msg.ts);
} else if (type === "entered" || type === "pdsTime" || type === "pdmTime" || type === "date") {
let data = node.positionConfig.getTimeProp(node, msg, type, value, offset, 1, days);
if (!data.error) {
format = format || 0;
switch (Number(format)) {
case 0: //timeformat_UNIX - milliseconds since Jan 1, 1970 00:00
return data.value.getTime();
case 1: //timeformat_ECMA262 - date as string ECMA-262
return data.value;
case 2: //timeformat_local
return data.value.toLocaleString();
case 3: //timeformat_localTime
return data.value.toLocaleTimeString();
case 4: //timeformat_UTC
return data.value.toUTCString();
case 5: //timeformat_ISO
return data.value.toISOString();
case 6: //timeformat_ms
return tsGetScheduleTime(data.value, (type === "date") ? 10 : undefined);
case 7: //timeformat_sec
return Math.round(tsGetScheduleTime(data.value, (type === "date") ? 10 : undefined) / 1000);
case 8: //timeformat_min
return (Math.round(tsGetScheduleTime(data.value, (type === "date") ? 10 : undefined) / 1000) / 60);
case 9: //timeformat_hour
return (Math.round(tsGetScheduleTime(data.value, (type === "date") ? 10 : undefined) / 1000) / 3600);
case 10: //timeformat_YYYYMMDDHHMMSS
return getforamtDateCmp(data.value);
case 11: //timeformat_YYYYMMDD_HHMMSS
return getforamtDateCmp2(data.value);
default:
let obj = data;
obj.name = value;
obj.offset = offset;
obj.allowedDays = days;
obj.ts = data.value.getTime();
obj.timeUTCStr = data.value.toUTCString();
obj.timeISOStr = data.value.toISOString();
obj.timeLocaleStr = data.value.toLocaleString();
obj.timeLocaleTimeStr = data.value.toLocaleTimeString();
let delay = tsGetScheduleTime(data.value, (type === "date") ? 10 : undefined);
obj.delay = delay;
obj.delaySec = Math.round(delay / 1000);
return obj;
}
}
return data;
}
return RED.util.evaluateNodeProperty(value, type, node, msg);
}
function tsSetAddProp(node, msg, type, name, valueType, value, format, offset, days) {
if (type !== 'none' && name) {
let res = tsGetPropData(node, msg, valueType, value, format, offset, days);
if (res == null || (typeof res === 'undefined')) {
throw new Error("could not evaluate " + valueType + '.' + value);
} else if (res.error) {
this.error('error on getting additional payload 1: ' + res.error);
} else if (type === 'msg' || type === 'msgProperty') {
RED.util.setMessageProperty(msg, name, res);
} else if ((type === 'flow' || type === 'global')) {
let contextKey = RED.util.parseContextStore(name);
node.context()[type].set(contextKey.key, res, contextKey.store);
}
}
}
function timeInjectNode(config) {

@@ -21,11 +135,8 @@ RED.nodes.createNode(this, config);

this.payload = config.payload || '';
this.payloadType = config.payloadType || 'none';
this.topic = config.topic;
this.time = config.time;
this.timeType = config.timeType || 'none';
this.timeDays = config.timeDays;
this.offset = config.offset || 0;
this.offsetMultiplier = config.offsetMultiplier || 60;
this.timeAltDays = config.timeAltDays;
this.offset = config.offset || config.timeOffset || 0;
this.offsetMultiplier = config.offsetMultiplier || config.timeOffsetMultiplier || 60;

@@ -41,5 +152,2 @@ this.property = config.property || '';

this.once = config.once;
this.onceDelay = (config.onceDelay || 0.1) * 1000;
this.timeOutObj = null;

@@ -53,11 +161,2 @@ this.intervalObj = null;

this.getScheduleTime = (time) => {
var now = new Date();
var millis = time.getTime() - now.getTime();
while (millis < 10) {
millis += 86400000; //24h
}
return millis;
}
function doCreateTimeout(node, msg) {

@@ -96,3 +195,3 @@ let errorStatus = '';

node.positionConfig) {
node.nextTimeAltData = node.positionConfig.getTimeProp(node, undefined, node.timeAltType, node.timeAlt, node.timeAltOffset * node.timeAltOffsetMultiplier, 1, node.timeDays);
node.nextTimeAltData = node.positionConfig.getTimeProp(node, undefined, node.timeAltType, node.timeAlt, node.timeAltOffset * node.timeAltOffsetMultiplier, 1, node.timeAltDays);
if (node.nextTimeAltData.error) {

@@ -115,55 +214,50 @@ errorStatus = "could not evaluate alternate time";

}
let millis = node.getScheduleTime(node.nextTime);
if (millis > 500) {
//node.debug('timeout ' + node.nextTime + ' is in ' + millis + 'ms');
let isAlt = (node.nextTimeAlt);
let millis = tsGetScheduleTime(node.nextTime, 10);
//node.debug('timeout ' + node.nextTime + ' is in ' + millis + 'ms');
let isAlt = (node.nextTimeAlt);
if (isAlt) {
let millisAlt = tsGetScheduleTime(node.nextTimeAlt, 10);
if (millisAlt < millis) {
millis = millisAlt;
isAltFirst = true;
}
}
node.timeOutObj = setTimeout((isAlt, isAltFirst) => {
let msg = {
type: 'start',
timeData: {}
};
node.timeOutObj = null;
let useAlternateTime = false;
if (isAlt) {
let millisAlt = node.getScheduleTime(node.nextTimeAlt);
if (millisAlt < millis) {
millis = millisAlt;
isAltFirst = true;
let needsRecalc = false;
try {
let res = RED.util.evaluateNodeProperty(node.property, node.propertyType, node, msg);
useAlternateTime = ((res == true) || (res == 'true'));
needsRecalc = (isAltFirst && !useAlternateTime) || (!isAltFirst && useAlternateTime);
} catch (err) {
needsRecalc = isAltFirst;
hlp.errorHandler(node, err, RED._("time-inject.errors.invalid-property-type", {
type: node.propertyType,
value: node.property
}));
node.log('Error: ' + util.inspect(err));
}
}
node.timeOutObj = setTimeout((isAlt, isAltFirst) => {
let msg = {
type: 'start',
timeData: {}
};
node.timeOutObj = null;
let useAlternateTime = false;
if (isAlt) {
let needsRecalc = false;
if (needsRecalc) {
try {
let res = RED.util.evaluateNodeProperty(node.property, node.propertyType, node, msg);
useAlternateTime = ((res == true) || (res == 'true'));
needsRecalc = (isAltFirst && !useAlternateTime) || (!isAltFirst && useAlternateTime);
doCreateTimeout(node, msg);
} catch (err) {
needsRecalc = isAltFirst;
hlp.errorHandler(node, err, RED._("time-inject.errors.invalid-property-type", {
type: node.propertyType,
value: node.property
}));
node.log(util.inspect(err));
hlp.errorHandler(node, err, RED._("time-inject.errors.error-text"), RED._("time-inject.errors.error-title"));
}
if (needsRecalc) {
try {
doCreateTimeout(node, msg);
} catch (err) {
hlp.errorHandler(node, err, RED._("time-inject.errors.error-text"), RED._("time-inject.errors.error-title"));
}
return;
}
return;
}
if (useAlternateTime && node.nextTimeAltData) {
msg.timeData = node.nextTimeAltData;
} else if (node.nextTimeData) {
msg.timeData = node.nextTimeData;
}
//node.debug('redo doCreateTimeout');
node.emit("input", msg);
}, millis, isAlt, isAltFirst);
} else {
errorStatus = "invalid calculated time";
node.nextTime = null;
}
}
if (useAlternateTime && node.nextTimeAltData) {
msg.timeData = node.nextTimeAltData;
} else if (node.nextTimeData) {
msg.timeData = node.nextTimeData;
}
//node.debug('redo doCreateTimeout');
node.emit("input", msg);
}, millis, isAlt, isAltFirst);
}

@@ -212,3 +306,3 @@

this.on('close', function () {
this.on('close', function() {
if (node.timeOutObj) {

@@ -227,44 +321,17 @@ clearTimeout(node.timeOutObj);

node.debug('input ' + util.inspect(msg));
let plType = 'date';
let plValue = '';
msg.topic = config.topic;
if (this.timeType !== 'none') {
plType = this.payloadType;
plValue = this.payload;
let value = tsGetPropData(this, msg, config.payloadType, config.payload);
if (value == null || (typeof value === 'undefined')) {
throw new Error("could not evaluate " + config.payloadType + '.' + config.payload);
} else if (value.error) {
throw new Error('could not getting payload: ' + value.error);
} else {
msg.payload = value;
}
msg.topic = this.topic;
if (plType == null || plType === "date" || plType === "none" || plType === "") {
if (plValue === "") {
msg.payload = Date.now();
} else {
msg.payload = plValue;
}
} else if (plType === "pdsCalcData") {
msg.payload = this.positionConfig.getSunCalc(msg.ts);
} else if (plType === "pdmCalcData") {
msg.payload = this.positionConfig.getMoonCalc(msg.ts);
} else if (plType === "pdsTime" || plType === "pdmTime") {
msg.timeData = this.positionConfig.getTimeProp(node, msg, plType,plValue, undefined, 1);
if (msg.timeData.error) {
hlp.errorHandler(node, err, RED._("time-inject.errors.error-text"), RED._("time-inject.errors.error-title"));
return null;
}
msg.payload = msg.timeData.value;
msg.timeName = plValue;
msg.timeStr = msg.timeData.value.toLocaleString();
msg.timeUTCStr = msg.timeData.value.toUTCString();
msg.timeOffsetMs = node.getScheduleTime(msg.timeData.value);
msg.timeOffsetSec = Math.round(msg.timeOffsetMs / 1000);
msg.timeOffsetMin = Math.round(msg.timeOffsetSec / 60);
} else {
RED.util.evaluateNodeProperty(plValue, plType, this, msg, function (err, res) {
if (err) {
hlp.errorHandler(node, err, RED._("time-inject.errors.error-text"), RED._("time-inject.errors.error-title"));
return null;
} else {
msg.payload = res;
}
});
}
tsSetAddProp(this, msg, config.addPayload1Type, config.addPayload1, config.addPayload1ValueType, config.addPayload1Value, config.addPayload1Format, config.addPayload1Offset, config.addPayload1Days);
tsSetAddProp(this, msg, config.addPayload2Type, config.addPayload2, config.addPayload2ValueType, config.addPayload2Value, config.addPayload2Format, config.addPayload2Offset, config.addPayload2Days);
tsSetAddProp(this, msg, config.addPayload3Type, config.addPayload3, config.addPayload3ValueType, config.addPayload3Value, config.addPayload3Format, config.addPayload3Offset, config.addPayload3Days);
node.send(msg);

@@ -277,4 +344,4 @@ } catch (err) {

try {
if (this.once) {
this.onceTimeout = setTimeout(function () {
if (config.once) {
config.onceTimeout = setTimeout(function() {
node.emit("input", {

@@ -284,3 +351,3 @@ type: 'once'

doCreateTimeout(node, undefined);
}, this.onceDelay);
}, (config.onceDelay || 0.1) * 1000);
} else {

@@ -287,0 +354,0 @@ doCreateTimeout(node, undefined);

{
"name": "node-red-contrib-sun-position",
"version": "0.1.14-beta.7",
"version": "0.1.16",
"description": "NodeRED nodes to get sun and moon position",

@@ -5,0 +5,0 @@ "main": "none",

@@ -271,2 +271,29 @@ # node-red-contrib-sun-position for NodeRED

- **Set additional** With this selection you can
- set __global__, __flow__ context or set additional property of the message object (if the property is __payload__ the payload will be overridden.)
- for any timestamp properties like __timestamp__, __sun time__, __moon time__ there are a lot of possibilities to influence this. You can add an offset or select the days wherfor the timestamp should be calculated. The output format could be Unix, ECMA timestamp, object or the time difference between timestamp and emit the message. This is useful to to send a payload of true on sunset with an additional message oprperty as __on time__ with the seconds until sunrise.
- **set additional timestamp**:
![time-inject](images/time-inject-settings-addProp1.png?raw=true)
- **set additional sun timestamp**:
![time-inject](images/time-inject-settings-addProp2.png?raw=true)
- **possible formates of timestamp output**
- number - milliseconds UNIX timestamp
- string - ECMA-262
- string - local date and time
- string - local time
- string - UTC date and time
- string - ISO date and time
- string - YYYYMMDDHHMMSS
- string - YYYYMMDD.HHMMSS
- number - milliseconds since emit
- number - seconds since emit
- number - minutes since emit
- number - hour since emit
- as object
time-inject-settings-addProp1
If this checkbox is set the inject node
#### Node Input

@@ -273,0 +300,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc