Socket
Socket
Sign inDemoInstall

node-red-contrib-sun-position

Package Overview
Dependencies
Maintainers
1
Versions
136
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-red-contrib-sun-position - npm Package Compare versions

Comparing version 0.2.9 to 0.2.10

images/sun-times.png

170

nodes/lib/dateTimeHelper.js

@@ -8,7 +8,14 @@ /********************************************

module.exports = {
isBool,
isTrue,
isFalse,
countDecimals,
handleError,
chkValueFilled,
checkLimits,
getMsgBoolValue,
getMsgNumberValue,
getSpecialDayOfMonth,
checkLimits,
getStdTimezoneOffset,
isDSTObserved,
addOffset,

@@ -36,3 +43,13 @@ calcDayOffset,

/*******************************************************************************************************/
/**
* returns **true** if the parameter value is a valid boolean value for **false** or **true**
* @param {*} val a parameter which should be checked if it is a valid false boolean
* @returns {boolean} true if the parameter value is a valid boolean value for for **false** or **true**
*/
function isBool(val) {
val = (val+'').toLowerCase();
return (['true', 'yes', 'on', 'ja', 'false', 'no', 'off', 'nein'].includes(val) || !isNaN(val));
}
/**
* returns **true** if the parameter value is a valid boolean value for **true**

@@ -44,3 +61,3 @@ * @param {*} val a parameter which should be checked if it is a valid true boolean

val = (val+'').toLowerCase();
return (val === 'true' || val === 'yes' || val === 'on' || val === 'ja' || val === '1' || (!isNaN(val) && (Number(val) > 0)));
return (['true', 'yes', 'on', 'ja'].includes(val) || (!isNaN(val) && (Number(val) > 0)));
}

@@ -55,4 +72,12 @@

val = (val+'').toLowerCase();
return (val === 'false' || val === 'no' || val === 'off' || val === 'nein' || val === '0' || (!isNaN(val) && (Number(val) <= 0)));
return (['false', 'no', 'off', 'nein'].includes(val) || (!isNaN(val) && (Number(val) <= 0)));
}
/**
* count the number of decimals of a number
* @param {*} value number to check
*/
function countDecimals(value) {
return value === value>> 0 ? 0 : value.toString().split('.')[1].length || 0;
}
/*******************************************************************************************************/

@@ -130,2 +155,12 @@ /**

/**
* check if a value is filled or returns default value
* @param {any} val to check for undefined, null, empty
* @param {any} defaultVal default value to use
* @returns {any} result to use if value is undefined, null or empty string
*/
function chkValueFilled(val, defaultVal) {
return ((typeof val === 'undefined') || (val === '') || (val === null)) ? defaultVal : val;
}
/*******************************************************************************************************/
/**
* get a date for the first day of week in the given month

@@ -274,3 +309,2 @@ * @param {number} year year to check

function checkLimits(num, low, high) {
// console.debug('checkLimits num=' + num + ' low=' + low + ' high=' + high); // eslint-disable-line
if (typeof low !== 'undefined' && low !== '' && !isNaN(low) && low >= 0) {

@@ -281,4 +315,6 @@ if (typeof high !== 'undefined' && high !== '' && !isNaN(high) && high >= 0) {

}
return (num > low) || (num < high);
}
return (num > low);

@@ -290,6 +326,123 @@ }

}
return false;
}
/**
* check the type of the message
* @param {*} msg message
* @param {*} name property name
*/
function getMsgNumberValue(msg, ids, names, isFound, notFound) {
if (ids) {
if (!Array.isArray(ids)) {
ids = [ids];
}
for (let i = 0; i < ids.length; i++) {
const id = ids[i];
if (typeof msg.payload[id] !== 'undefined') {
const res = parseFloat(msg.payload[id]);
if (!isNaN(res)) {
if (typeof isFound === 'function') {
return isFound(res);
}
return res;
}
}
if (typeof msg[id] !== 'undefined') {
const res = parseFloat(msg[id]);
if (!isNaN(res)) {
if (typeof isFound === 'function') {
return isFound(res);
}
return res;
}
}
}
}
// includes
if (names && msg.topic) {
const res = parseFloat(msg.payload);
if (!isNaN(res)) {
if (!Array.isArray(names)) {
names = [names];
}
for (let i = 0; i < names.length; i++) {
if (String(msg.topic).toLowerCase().includes(names[i])) {
const res = parseFloat(msg.payload);
if (!isNaN(res)) {
if (typeof isFound === 'function') {
return isFound(res);
}
return res;
}
}
}
}
}
if (typeof notFound === 'function') {
return notFound(msg);
}
return notFound || NaN;
}
/**
* check the type of the message
* @param {*} msg message
* @param {*} name property name
*/
function getMsgBoolValue(msg, ids, names, isFound, notFound) {
if (ids) {
if (!Array.isArray(ids)) {
ids = [ids];
}
for (let i = 0; i < ids.length; i++) {
const id = ids[i];
if ((typeof msg.payload[id] !== 'undefined') && (msg.payload[id] !== null) && (msg.payload[id] !== '')) {
if (typeof isFound === 'function') {
return isFound(isTrue(msg.payload[id]));
}
return isTrue(msg.payload[id]);
}
if ((typeof msg[id] !== 'undefined') && (msg[id] !== null) && (msg[id] !== '')) {
if (typeof isFound === 'function') {
return isFound(isTrue(msg[id]));
}
return isTrue(msg[id]);
}
}
}
if (names && msg.topic && ((typeof msg.payload === 'string') || (typeof msg.payload === 'number'))) {
if (!Array.isArray(names)) {
names = [names];
}
for (let i = 0; i < names.length; i++) {
if (String(msg.topic).toLowerCase().includes(names[i])) {
if (typeof isFound === 'function') {
return isFound(isTrue(msg.payload));
}
return isTrue(msg.payload);
}
}
}
if (typeof notFound === 'function') {
return notFound(msg);
}
return notFound || NaN;
}
/*******************************************************************************************************/
function getStdTimezoneOffset(d) {
d = d || new Date();
const jan = new Date(d.getFullYear(),0,1);
const jul = new Date(d.getFullYear(), 6, 1);
return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
}
function isDSTObserved(d) {
d = d || new Date();
return d.getTimezoneOffset() < getStdTimezoneOffset(d);
}
/*******************************************************************************************************/
/**

@@ -330,3 +483,4 @@ * adds an offset to a given Date object

let daypos = daystart;
while (days.indexOf(daypos) === -1) {
// while (days.indexOf( ) === -1) {
while (!days.includes(daypos)) {
dayx += 1;

@@ -389,3 +543,4 @@ if ((daystart + dayx) > 6) {

const d = date || new Date();
if (t && (t.indexOf('.') === -1) && (t.indexOf('-') === -1)) {
// if (t && (t.indexOf('.') === -1) && (t.indexOf('-') === -1)) {
if (t && (!t.includes('.')) && (!t.includes('-'))) {
const matches = t.match(/(0\d|1\d|2[0-3]|\d)(?::([0-5]\d|\d))(?::([0-5]\d|\d))?\s*(p?)/);

@@ -858,3 +1013,4 @@ if (matches) {

for (let i = 0; i < val.length; i++) {
if (digits.indexOf(val.charAt(i)) === -1) {
// if (digits.indexOf(val.charAt(i)) === -1) {
if (!digits.includes(val.charAt(i))) {
return false;

@@ -861,0 +1017,0 @@ }

22

nodes/lib/suncalc.js

@@ -13,27 +13,15 @@ /*

// shortcuts for easier to read formulas
const PI = Math.PI;
const sin = Math.sin;
const cos = Math.cos;
const tan = Math.tan;
const asin = Math.asin;
const atan = Math.atan2;
const acos = Math.acos;
const rad = PI / 180;
// sun calculations are based on http://aa.quae.nl/en/reken/zonpositie.html formulas
// date/time constants and conversions
const dayMs = 1000 * 60 * 60 * 24;
const J1970 = 2440588;
const J2000 = 2451545;

@@ -86,5 +74,3 @@

}
// general sun calculations
function solarMeanAnomaly(d) {

@@ -97,5 +83,3 @@ return rad * (357.5291 + 0.98560028 * d);

// equation of center
const P = rad * 102.9372; // perihelion of the Earth
return M + C + P + PI;

@@ -106,3 +90,2 @@ }

const M = solarMeanAnomaly(d);
const L = eclipticLongitude(M);

@@ -129,11 +112,6 @@

const lw = rad * -lng;
const phi = rad * lat;
const d = toDays(date);
const c = sunCoords(d);
const H = siderealTime(d, lw) - c.ra;
return {

@@ -140,0 +118,0 @@ azimuth: azimuth(H, phi, c.dec),

{
"moon-position": {
"label": {
"azimuthpos":"azimuth Position",
"between":"zwischen",

@@ -6,0 +5,0 @@ "and":"und"

@@ -25,3 +25,5 @@ {

"suncalc": "Sonnenposition",
"mooncalc": "Mondposition"
"mooncalc": "Mondposition",
"levelfix": "Position",
"levelfree": "Position eingeben"
},

@@ -159,2 +161,11 @@ "multiselectLbl": {

],
"blindOperatorGroups": [
"Rollladen Position einschränken",
"feste position"
],
"blindOperator": [
"minimal",
"maximal",
"absolut"
],
"days": [

@@ -166,3 +177,3 @@ "Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Sonnabend",

"Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember",
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
"Jan", "Feb", "März", "Apr", "Mai", "Jun", "Jul", "Aug", "Sept", "Okt", "Nov", "Dez"
],

@@ -204,10 +215,11 @@ "dayDiffNames": [

"tips": {
"config": "Starting from Version 2.0 the coordinates are not saved as credentials due to privacy reasons. So they no longer part of the regular flow and will not part of the export! On an update from previous version a save and re-deploy is necessary.",
"config": "Starting from Version 2.0 the coordinates are not saved as credentials due to privacy reasons. So they no longer part of the regular flow and will not part of the export! To update from a previous version save and re-deploy is necessary.",
"sunPosControl": "Here you can specify the upper and lower limits for the solar radiation so that you can evaluate the sunshine on 4 sides of an object."
},
"errors": {
"longitude-missing": "Longitude is missing!",
"latitude-missing": "Latitude is missing!"
"longitude-missing": "Koordinate Longitude fehlt oder ist falsch!",
"latitude-missing": "Koordinate Latitude fehlt oder ist falsch!",
"coordinates-missing": "Koordinaten Latitude and Longitude ist falsch!"
}
}
}

@@ -7,2 +7,3 @@ {

"and":"und",
"name": "Name",
"start": "Start",

@@ -9,0 +10,0 @@ "startOffset":"Start Offset",

{
"moon-position": {
"label": {
"azimuthpos":"azimuth Position",
"between":"between",

@@ -6,0 +5,0 @@ "and":"and"

@@ -25,3 +25,5 @@ {

"suncalc":"sun calculation",
"mooncalc":"moon calculation"
"mooncalc":"moon calculation",
"levelfix":"Level",
"levelfree": "Level entered"
},

@@ -159,2 +161,11 @@ "multiselectLbl": {

],
"blindOperatorGroups": [
"limit blind position",
"fixed position"
],
"blindOperator": [
"minimum",
"maximum",
"absolute"
],
"days": [

@@ -203,3 +214,5 @@ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",

"error-init": "error '__message__', retry in __time__min",
"warn-init": "warning '__message__', retry in __time__min"
"warn-init": "warning '__message__', retry in __time__min",
"pos-config": "Node not properly configured!! Missing or wrong position configuration!",
"pos-config-state": "Node not properly configured!!"
},

@@ -225,10 +238,11 @@ "position-config": {

"tips": {
"config": "Starting from Version 2.0 the coordinates are not saved as credentials due to privacy reasons. So they no longer part of the regular flow and will not part of the export! On an update from previous version a save and re-deploy is necessary.",
"config": "Starting from Version 2.0 the coordinates are not saved as credentials due to privacy reasons. So they no longer part of the regular flow and will not part of the export! To update from a previous version save and re-deploy is necessary.",
"sunPosControl": "Here you can specify the upper and lower limits for the solar radiation so that you can evaluate the sunshine on 4 sides of an object."
},
"errors": {
"longitude-missing": "Longitude is missing!",
"latitude-missing": "Latitude is missing!"
"longitude-missing": "Longitude is missing or wrong!",
"latitude-missing": "Latitude is missing or wrong!",
"coordinates-missing": "Latitude and Longitude is wrong!"
}
}
}
{
"sun-position": {
"label": {
"azimuthpos":"azimuth Position",
"azimuthpos":"azimuth position",
"between":"between",
"and":"and",
"name": "Name",
"start": "Start",

@@ -8,0 +9,0 @@ "startOffset":"Start Offset",

@@ -53,6 +53,24 @@ {

},
<<<<<<< HEAD
"errors": {
"error": "<strong>Error</strong>: __message__",
"error-text": "Exception occurred 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",
"error-init": "error '__message__', retry in __time__",
"warn-init": "warning '__message__', retry in __time__"
=======
"errors":{
"invalid-property-type": "Invalid Property Type: __type__"
>>>>>>> i18n
}
}
}

@@ -24,7 +24,23 @@ /********************************************

try {
const errorStatus = '';
let now = new Date();
if (typeof msg.time !== 'undefined') {
now = new Date(msg.time);
}
if (typeof msg.ts !== 'undefined') {
now = new Date(msg.time);
}
if (!this.positionConfig) {
node.error(RED._('node-red-contrib-sun-position/position-config:errors.pos-config'));
node.status({
fill: 'red',
shape: 'dot',
text: RED._('node-red-contrib-sun-position/position-config:errors.pos-config-state')
});
return null;
}
const ports = new Array(this.rules.length);
ports[0] = {
payload: this.positionConfig.getMoonCalc(msg.ts),
topic: this.topic
};
ports[0] = RED.util.cloneMessage(msg);
ports[0].payload = this.positionConfig.getMoonCalc(now);
ports[0].topic = this.topic;
if (!ports[0].payload.azimuth) {

@@ -48,15 +64,32 @@ this.error('Azimuth could not calculated!');

ports[i + 1] = RED.util.cloneMessage(msg);
ports[i + 1].moonPos = chk;
ports[i + 1].payload.moonPos = chk;
ports[i + 1].payload.posChanged = chg;
ports[i + 1].posChanged = chg;
ports[i + 1].azimuth = ports[0].payload.azimuth;
}
}
node.azimuthPos = ports[0].payload.pos;
node.azimuthPos = ports[0].payload.pos;
this.send(ports);
this.status({
fill: 'grey',
shape: 'dot',
text: ports[0].payload.azimuth.toFixed(2) + '/' + ports[0].payload.altitude.toFixed(2) + ' - ' + ports[0].payload.lastUpdate.toLocaleString()
});
if (errorStatus) {
this.status({
fill: 'red',
shape: 'dot',
text: errorStatus
});
} else {
let fill = 'red';
let text = 'no Data loaded!';
if (ports[0] && ports[0].payload && ports[0].payload.lastUpdate) {
const azimuth = (ports[0].payload.azimuth) ? ports[0].payload.azimuth.toFixed(2) : '?';
const altitude = (ports[0].payload.altitude) ? ports[0].payload.altitude.toFixed(2) : '?';
text = azimuth + '/' + altitude + ' - ' + ports[0].payload.lastUpdate.toLocaleString();
fill = 'grey';
}
this.status({
fill: fill,
shape: 'dot',
text: text
});
}
this.send(ports); // Warning change msg object!!
return null;

@@ -72,15 +105,28 @@ } catch (err) {

}
// this.error("Input parameter wrong or missing. You need to setup (or give in the input message) the 'url' and 'content type' or the 'message' and 'language'!!");
// this.status({fill:"red",shape:"dot",text:"error - input parameter"});
});
function getNumProp(srcNode, msg, vType, value) {
try {
if (vType === 'none') {
return undefined;
// srcNode.debug('getNumProp vType=' + vType + ' value=' + value);
const now = new Date();
let result = -1;
if (vType === '' || vType === 'none') {
// nix
} else if (vType === 'num') {
result = Number(now);
} else {
try {
// evaluateNodeProperty(value, type, srcNode, msg, callback)
const res = RED.util.evaluateNodeProperty(value, vType, srcNode, msg);
if (res && !isNaN(res)) {
result = Number(now);
} else {
srcNode.error('could not evaluate ' + vType + '.' + value);
}
} catch (err) {
srcNode.error('could not evaluate ' + vType + '.' + value + ': ' + err.message);
srcNode.debug(util.inspect(err, Object.getOwnPropertyNames(err)));
}
return node.positionConfig.getFloatProp(node, msg, vType, value);
} catch (err) {
return undefined;
}
return result;
}

@@ -87,0 +133,0 @@ }

@@ -98,2 +98,3 @@ /********************************************

} else if (next > 1) {
checkCoordinates(node);
const date = (new Date()).addDays(next);

@@ -110,2 +111,3 @@ result = Object.assign(result, sunCalc.getTimes(date, node.latitude, node.longitude)[value]);

if (dayx > 0) {
checkCoordinates(node);
const date = result.value.addDays(dayx);

@@ -135,2 +137,3 @@ // let times = sunCalc.getTimes(date, node.latitude, node.longitude);

} else if (next > 1) {
checkCoordinates(node);
const date = (new Date()).addDays(next);

@@ -146,2 +149,3 @@ const times = sunCalc.getMoonTimes(date, node.latitude, node.longitude, true);

if (dayx > 0) {
checkCoordinates(node);
const date = (new Date()).addDays(dayx);

@@ -379,5 +383,6 @@ const times = sunCalc.getMoonTimes(date, node.latitude, node.longitude, true);

/**************************************************************************************************************/
this.getSunCalc = date => {
this.getSunCalc = (date, noTimes) => {
// node.debug(`getSunCalc for date="${date}" noTimes="${noTimes}"`);
if (typeof date === 'string') {
// node.debug('getSunCalc for date ' + date);
node.debug('getSunCalc for date ' + date);
const dto = new Date(date);

@@ -390,6 +395,6 @@ if (dto !== 'Invalid Date' && !isNaN(dto)) {

if ((typeof date === 'undefined') || !(date instanceof Date)) {
// node.debug('getSunCalc, no valid date ' + date + ' given');
node.debug('getSunCalc, no valid date ' + date + ' given');
date = new Date();
if (Math.abs(date.getTime() - this.lastSunCalc.ts) < 4000) {
// node.debug('getSunCalc, time difference since last output to low, do no calculation');
if (this.lastSunCalc && (Math.abs(date.getTime() - this.lastSunCalc.ts) < 4000)) {
node.debug('getSunCalc, time difference since last output to low, do no calculation');
return this.lastSunCalc;

@@ -416,6 +421,11 @@ }

};
if (noTimes) {
// node.debug('no times result= ' + util.inspect(result));
return result;
}
sunTimesCheck(node);
result.times = node.sunTimesToday;
this.lastSunCalc = result;
// node.debug('result= ' + util.inspect(result));
return result;

@@ -425,3 +435,3 @@ };

/**************************************************************************************************************/
this.getMoonCalc = date => {
this.getMoonCalc = (date, noTimes) => {
if (typeof date === 'string') {

@@ -436,3 +446,3 @@ const dto = new Date(date);

date = new Date();
if (Math.abs(date.getTime() - this.lastMoonCalc.ts) < 3000) {
if (this.lastMoonCalc (Math.abs(date.getTime() - this.lastMoonCalc.ts) < 3000)) {
return this.lastMoonCalc;

@@ -462,5 +472,2 @@ }

};
sunTimesCheck(node);
result.times = node.moonTimesToday;
// getAngle : angle / 57.2957795130823209 //angle(rad) * (180° / Pi) = angle(deg)

@@ -496,2 +503,7 @@ if (moonIllum.phase < 0.01) {

if (noTimes) { return result; }
sunTimesCheck(node);
result.times = node.moonTimesToday;
// getAngle : angle / 57.2957795130823209 //angle(rad) * (180° / Pi) = angle(deg)
if (!result.times.alwaysUp) {

@@ -531,9 +543,16 @@ // true if the moon never rises/sets and is always above the horizon during the day

/**************************************************************************************************************/
function sunTimesRefresh(node, today, tomorrow, dayId) {
if (isNaN(node.longitude)) {
function checkCoordinates(node) {
if (isNaN(node.longitude) || (node.longitude < -180) || (node.longitude > 180)) {
throw new Error(RED._('position-config.errors.longitude-missing'));
}
if (isNaN(node.latitude)) {
if (isNaN(node.latitude) || (node.latitude < -90) || (node.latitude > 90)) {
throw new Error(RED._('position-config.errors.latitude-missing'));
}
if ((node.latitude === 0) && (node.longitude === 0)) {
throw new Error(RED._('position-config.errors.coordinates-missing'));
}
}
function sunTimesRefresh(node, today, tomorrow, dayId) {
checkCoordinates(node);
// node.debug('sunTimesRefresh - calculate sun times');

@@ -561,8 +580,3 @@ node.sunTimesToday = sunCalc.getTimes(today, node.latitude, node.longitude);

function moonTimesRefresh(node, today, tomorrow, dayId) {
if (isNaN(node.longitude)) {
throw new Error(RED._('position-config.errors.longitude-missing'));
}
if (isNaN(node.latitude)) {
throw new Error(RED._('position-config.errors.latitude-missing'));
}
checkCoordinates(node);
// node.debug('moonTimesRefresh - calculate moon times');

@@ -569,0 +583,0 @@ node.moonTimesToday = sunCalc.getMoonTimes(today, node.latitude, node.longitude, true);

@@ -98,2 +98,9 @@ /************************************************************************/

{id: -2, group: 'other', label: 'year'}
], blindOperatorGroups: [
{ id: 'limit', label: 'Limit' },
{ id: 'other', label: 'fix' }
], blindOperator: [
{ id: 1, group: 'limit', label: 'min' },
{ id: 2, group: 'limit', label: 'max' },
{ id: 0, group: 'other', label: 'abs' }
]

@@ -238,2 +245,6 @@ };

function getSelectFields() { // eslint-disable-line no-unused-vars
return SelectFields;
}
const autocompleteFormats = {

@@ -423,3 +434,9 @@ dateParseFormat : [

const groups = SelectFields[elementName + 'Groups'];
if (!groups) {
throw new Error('no group "' + elementName + 'Groups" in SelectFields found!');
}
const elements = SelectFields[elementName];
if (!groups) {
throw new Error('no elements "' + elementName + '" in SelectFields found!');
}
const groupLength = groups.length;

@@ -542,3 +559,3 @@ const elementsLength = elements.length;

function addLabel(row, forEl, symb, text) { // eslint-disable-line no-unused-vars
const lbl = $('<label class="' + forEl + '-lbl"/>').attr('for', forEl).appendTo(row);
const lbl = $('<label class="' + forEl + '-lbl" style="width:auto"/>').attr('for', forEl).appendTo(row);
if (symb) {

@@ -548,7 +565,7 @@ lbl.append('<i class= "' + symb + '" >');

if (text) {
const span = $('<span class="' + forEl + '-span" style="float: right; margin-left: 5px; */">' + text + '</span>');
const span = $('<span class="' + forEl + '-span" style="float: right; margin-left: 5px; margin-right: 2px;*/">' + text + '</span>');
lbl.append(span);
lbl.attr('style', 'margin-left: 5px; width:' + 20 + span.width() + 'px;');
} else {
lbl.attr('style', 'margin-left: 5px; width:20px');
lbl.attr('style', 'margin-left: 5px; margin-right: 2px; width:20px');
}

@@ -555,0 +572,0 @@ return lbl;

@@ -41,7 +41,16 @@ /********************************************

}
if (!this.positionConfig) {
node.error(RED._('node-red-contrib-sun-position/position-config:errors.pos-config'));
node.status({
fill: 'red',
shape: 'dot',
text: RED._('node-red-contrib-sun-position/position-config:errors.pos-config-state')
});
return null;
}
const ports = new Array(this.rules.length);
ports[0] = {
payload: this.positionConfig.getSunCalc(msg.ts),
topic: this.topic
};
ports[0] = RED.util.cloneMessage(msg);
ports[0].payload = this.positionConfig.getSunCalc(now);
ports[0].topic = this.topic;
if (!ports[0].payload.azimuth) {

@@ -94,10 +103,8 @@ this.error('Azimuth could not calculated!');

ports[i + 1] = RED.util.cloneMessage(msg);
ports[i + 1].sunPos = chk;
ports[i + 1].payload.sunPos = chk;
ports[i + 1].payload.posChanged = chg;
ports[i + 1].posChanged = chg;
ports[i + 1].azimuth = ports[0].payload.azimuth;
}
}
node.azimuthPos = ports[0].payload.pos;
this.send(ports);

@@ -127,8 +134,18 @@ if (errorStatus) {

} else {
let fill = 'red';
let text = 'no Data loaded!';
if (ports[0] && ports[0].payload && ports[0].payload.lastUpdate) {
const azimuth = (ports[0].payload.azimuth) ? ports[0].payload.azimuth.toFixed(2) : '?';
const altitude = (ports[0].payload.altitude) ? ports[0].payload.altitude.toFixed(2) : '?';
text = azimuth + '/' + altitude + ' - ' + ports[0].payload.lastUpdate.toLocaleString();
fill = 'grey';
}
this.status({
fill: 'grey',
fill: fill,
shape: 'dot',
text: ports[0].payload.azimuth.toFixed(2) + '/' + ports[0].payload.altitude.toFixed(2) + ' - ' + ports[0].payload.lastUpdate.toLocaleString()
text: text
});
}
this.send(ports); // Warning change msg object!!
return null;

@@ -144,15 +161,28 @@ } catch (err) {

}
// this.error("Input parameter wrong or missing. You need to setup (or give in the input message) the 'URL' and 'content type' or the 'message' and 'language'!!");
// this.status({fill:"red",shape:"dot",text:"error - input parameter"});
});
function getNumProp(srcNode, msg, vType, value) {
try {
if (vType === 'none') {
return undefined;
// srcNode.debug('getNumProp vType=' + vType + ' value=' + value);
const now = new Date();
let result = -1;
if (vType === '' || vType === 'none') {
// nix
} else if (vType === 'num') {
result = Number(now);
} else {
try {
// evaluateNodeProperty(value, type, srcNode, msg, callback)
const res = RED.util.evaluateNodeProperty(value, vType, srcNode, msg);
if (res && !isNaN(res)) {
result = Number(now);
} else {
srcNode.error('could not evaluate ' + vType + '.' + value);
}
} catch (err) {
srcNode.error('could not evaluate ' + vType + '.' + value + ': ' + err.message);
srcNode.debug(util.inspect(err, Object.getOwnPropertyNames(err)));
}
return node.positionConfig.getFloatProp(node, msg, vType, value);
} catch (err) {
return undefined;
}
return result;
}

@@ -159,0 +189,0 @@ }

@@ -0,0 +0,0 @@ /* eslint-disable */

@@ -0,0 +0,0 @@ [{

@@ -49,3 +49,2 @@ /********************************************

}
if (result.start.error) {

@@ -206,2 +205,11 @@ if (_onInit === true) {

try {
if (!node.positionConfig) {
node.error(RED._('node-red-contrib-sun-position/position-config:errors.pos-config'));
node.status({
fill: 'red',
shape: 'dot',
text: RED._('node-red-contrib-sun-position/position-config:errors.pos-config-state')
});
return null;
}
// this.debug('starting ' + util.inspect(msg, Object.getOwnPropertyNames(msg)));

@@ -265,2 +273,11 @@ // this.debug('self ' + util.inspect(this, Object.getOwnPropertyNames(this)));

try {
if (!node.positionConfig) {
node.error(RED._('node-red-contrib-sun-position/position-config:errors.pos-config'));
node.status({
fill: 'red',
shape: 'dot',
text: RED._('node-red-contrib-sun-position/position-config:errors.pos-config-state')
});
return null;
}
node.status({});

@@ -267,0 +284,0 @@ const result = calcWithinTimes(this, null, config);

{
"name": "node-red-contrib-sun-position",
"version": "0.2.9",
"version": "0.2.10",
"description": "NodeRED nodes to get sun and moon position",

@@ -89,3 +89,3 @@ "keywords": [

"dependencies": {
"util": ">=0.10.0"
"util": ">=0.8.0"
},

@@ -95,5 +95,12 @@ "devDependencies": {

"eslint": "^5.15.3",
"eslint-plugin-html": "^5.0.3",
"eslint-plugin-jsdoc": "^4.4.3"
"eslint-plugin-html": "^5.0.3"
},
"disabledSettings": {
"devDependencies-disabled": {
"eslint-plugin-jsdoc": "^4.4.3"
},
"plugins-disabled": [
"jsdoc"
]
},
"eslintConfig": {

@@ -100,0 +107,0 @@ "env": {

@@ -475,3 +475,3 @@ # node-red-contrib-sun-position for NodeRED

![sun times](images/sun-times.svg.png?raw=true)
![sun times](images/sun-times.png?raw=true)

@@ -478,0 +478,0 @@ ##### remarks

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc