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 1.0.8 to 1.0.9

36

CHANGELOG.md
# node-red-contrib-sun-position
#### 1.0.7: bug fix
#### 1.0.9: bug fix
- general
- fixed #102 again - massive changes in the library with cleanup lot of functions
- fixed and reworked caching of calculated sunTimes, MoonTimes
- blind-control + clock-time
- documentation
- if in startup delay, the reason code is set to `NaN` and node state, reason description stated that node is in startup
- after startup delay ended default output will be send (due to reason code change)
- clock-time
- additional to reason or rule change, the payload will also output on these changes
- if type of payload has changed
- if payload is of type `string`, `number` or `boolean` and value of the payload has changed
- changes on `arrays`, `objects` will not detected
#### 1.0.8: bug fix
- time-inject

@@ -18,4 +35,4 @@ - fixes that time inject will do a recalculation every 1 ms (Problem can only occurs if the time constraints are used.) #106

- blind-control + clock-time
- fixed start delay setting causing no output at all
- i18n, spelling, documentation
- fixed start delay setting causing no output at all
- i18n, spelling, documentation

@@ -25,9 +42,9 @@ #### 1.0.6: bug fix

- general
- fixed #102 - nodes calculate wrong sun times
- this happend between midnight - TimezoneOffset to midnight
- maybe fixes also #98
- fixed broken rule check for time-span #103
- fixed #102 - nodes calculate wrong sun times
- this happend between midnight - TimezoneOffset to midnight
- maybe fixes also #98
- fixed broken rule check for time-span #103
- blind-control + clock-time
- first implementation of #92 (needs more test)
- first implementation of #92 (needs more test)

@@ -37,5 +54,4 @@ #### 1.0.5: bug fix

- blind-control + clock-time
- add start delay setting where a time can be defined where no output
- add start delay setting where a time can be defined where no output
#### 1.0.4: bug fix

@@ -42,0 +58,0 @@

@@ -64,2 +64,13 @@ # clock-timer Controller

#### special settings
* **output** here is configurable if the node has one single (default) or two outputs. See [Node Output](#node-output) for further details.
* **auto trigger** Typically the calculation will be triggered by an incoming message or by an expiring timeout from an override. Additionally the node can be configured to have an auto trigger time.
* If such a time is configured the node will be trigger a new calculation automatically at the next possible time, taking the following times into account:
* a time for a rule or the next rule occurs or expires
* the configured time span in the node
* To thus in the most cases it makes no sense to enter a short period (less than 15min) of auto trigger time in the configuration, because the node automatically shortens the time if necessary.
* Please note that the node cannot react to changes in times that are configured via a context. If for example times or offsets configured by using a flow or global context, the auto trigger would not change the next trigger time.
* **start delay** Sometimes on node-red start (or flow re deploy) the node should not send any output before the system has settled (contexts are set, incoming messages processed, ...). To thus it is possible to define a delay time. Setting a time will only block the node to send any output until the time has reached to the first output. All calculations still will be made.
### Node Input

@@ -92,2 +103,3 @@

### Node Output

@@ -114,2 +126,3 @@

* `timeCtrl.reason.code` - __number__ - representing the reason for the blind position. The possible codes are
* **NaN** - start delay is setup and node is in this time
* **-1** - the rules was not evaluated, maybe override is active

@@ -163,3 +176,3 @@ * **1** - defined default payload, because no other rule/condition/behavior

* red - any error
* red - any error or a start delay is set and node is currently in this time
* blue - override active

@@ -166,0 +179,0 @@ * grey - payload by rule

@@ -419,3 +419,3 @@ /********************************************

prepareRules(node, msg, tempData);
// node.debug(`checkRules nowNr=${nowNr}, rules.count=${node.rules.count}, rules.lastUntil=${node.rules.lastUntil}`); // {colors:true, compact:10}
// node.debug(`checkRules now=${now.toISOString()}, nowNr=${nowNr}, rules.count=${node.rules.count}, rules.lastUntil=${node.rules.lastUntil}`); // {colors:true, compact:10}

@@ -468,3 +468,3 @@ const fktCheck = (rule, cmp) => {

const num = getRuleTimeData(node, msg, rule, now);
// node.debug(`pos=${rule.pos} type=${rule.timeOpText} - ${rule.timeValue} - rule.timeData = ${ util.inspect(rule.timeData, { colors: true, compact: 40, breakLength: Infinity }) }`);
// node.debug(`pos=${rule.pos} type=${rule.timeOpText} - ${rule.timeValue} - num=${num}- rule.timeData = ${ util.inspect(rule.timeData, { colors: true, compact: 40, breakLength: Infinity }) }`);
if (dayId === rule.timeData.dayId && num >=0 && cmp(num)) {

@@ -665,7 +665,8 @@ return rule;

const code = node.reason.code;
const shape = 'ring';
let shape = 'ring';
let fill = 'yellow';
if (node.startDelayTime) {
if (isNaN(code)) {
fill = 'red'; // block
shape = 'dot';
} else if (code <= 3) {

@@ -704,3 +705,2 @@ fill = 'blue'; // override

if (!this.positionConfig) {
// node.error(RED._('node-red-contrib-sun-position/position-config:errors.pos-config'));
node.status({

@@ -717,5 +717,12 @@ fill: 'red',

const previousData = node.context().get('previous',node.storeName) || {};
previousData.payloadType = (typeof node.payload.current);
previousData.reasonCode = node.reason.code;
previousData.reasonState = node.reason.state;
previousData.reasonDescription = node.reason.description;
if (previousData.payloadType === 'string' ||
previousData.payloadType === 'boolean' ||
previousData.payloadType === 'number') {
previousData.payloadValue = node.payload.current;
previousData.payloadSimple = true;
}
node.reason.code = NaN;

@@ -744,2 +751,8 @@ const now = hlp.getNowTimeStamp(node, msg);

timeCtrl.timeClock = node.timeClockData;
if (node.startDelayTime) {
node.reason.code = NaN;
node.reason.state = RED._('clock-timer.states.startDelay');
node.reason.description = RED._('clock-timer.reasons.startDelay');
}
setState(node.payload.current);

@@ -760,8 +773,10 @@

if (typeof node.payload.current !== 'undefined' &&
node.payload.current !== 'none' &&
node.payload.current !== null &&
if ((typeof node.payload.current !== 'undefined') &&
(node.payload.current !== 'none') &&
(node.payload.current !== null) &&
!isNaN(node.reason.code) &&
((node.reason.code !== previousData.reasonCode) ||
(ruleId !== previousData.usedRule)) &&
!node.startDelayTime) {
(ruleId !== previousData.usedRule) ||
(typeof node.payload.current !== previousData.payloadType) ||
((typeof previousData.payloadValue !== 'undefined') && (previousData.payloadValue !== node.payload.current))) ) {
msg.payload = node.payload.current;

@@ -768,0 +783,0 @@ msg.topic = topic;

@@ -29,39 +29,17 @@ /*

/**
* checks if a value is a valid Date object
* @param {*} d - a value to check
* @returns {boolean} returns __true__ if it is a valid Date, otherwhise __false__
*/
function isValidDate(d) {
return d instanceof Date && !isNaN(d);
// d !== 'Invalid Date' && !isNaN(d)
}
/**
* convert date from Julian calendar
* @param {*} date object to convert
* @return {date} result date
* @param {number} day nmber in julian calendar to convert
* @return {number} result date as unix timestamp
*/
function fromJulianDay(j) {
return new Date((j - J1970) * dayMs);
return (j - J1970) * dayMs;
}
/**
* get number of days for a date since 2000
* @param {Date} date date to get days
* @param {boolean} [inUTC] defines if the calculation should be in utc or local time (default is UTC)
* @return {number} cont of days
* get number of days for a dateValue since 2000
* @param {number} dateValue date as unix timestamp to get days
* @return {number} count of days
*/
function toDays(date, inUTC) {
if (!isValidDate(date)) {
console.log(`toDays: given date parameter is invalid!! date=${date}`); // eslint-disable-line no-console
date = new Date();
} else {
date = new Date(date);
}
let ms = date.valueOf();
if (inUTC === false) {
ms = ms + (date.getTimezoneOffset() * 60 * 1000);
}
return ((ms / dayMs) + J1970) - J2000;
function toDays(dateValue) {
return ((dateValue / dayMs) + J1970) - J2000;
}

@@ -192,10 +170,9 @@

* calculates sun position for a given date and latitude/longitude
* @param {Date} date Date object with the for calculating sun-position
* @param {number} dateValue date as unix timestamp for calculating sun-position
* @param {number} lat latitude for calculating sun-position
* @param {number} lng longitude for calculating sun-position
* @param {boolean} [inUTC] defines if the calculation should be in utc or local time (default is UTC)
* @return {sunposition} result object of sun-position
*/
SunCalc.getPosition = function (date, lat, lng, inUTC) {
// console.log(`getPosition date=${date.toISOString()} lat=${lat}, lng=${lng}, inUTC=${inUTC}`);
SunCalc.getPosition = function (dateValue, lat, lng) {
// console.log(`getPosition dateValue=${dateValue} lat=${lat}, lng=${lng}`);
if (isNaN(lat)) {

@@ -209,3 +186,3 @@ throw new Error('latitude missing');

const phi = rad * lat;
const d = toDays(date, inUTC);
const d = toDays(dateValue);
const c = sunCoords(d);

@@ -373,10 +350,9 @@ const H = siderealTime(d, lw) - c.ra;

* calculates sun times for a given date and latitude/longitude
* @param {Date} date Date object with the for calculating sun-times
* @param {number} dateValue date as unix timestamp for calculating sun-times
* @param {number} lat latitude for calculating sun-times
* @param {number} lng longitude for calculating sun-times
* @param {boolean} [inUTC] defines if the calculation should be in utc or local time (default is UTC)
* @return {suntimes} result object of sunTime
*/
SunCalc.getSunTimes = function (date, lat, lng, inUTC, noDeprecated) {
// console.log(`getSunTimes date=${date.toISOString()} lat=${lat}, lng=${lng}, inUTC=${inUTC}, noDeprecated=${noDeprecated}`);
SunCalc.getSunTimes = function (dateValue, lat, lng, noDeprecated) {
// console.log(`getSunTimes dateValue=${dateValue} lat=${lat}, lng=${lng}, noDeprecated=${noDeprecated}`);
if (isNaN(lat)) {

@@ -390,3 +366,3 @@ throw new Error('latitude missing');

const phi = rad * lat;
const d = toDays(date, inUTC);
const d = toDays(dateValue);
const n = julianCycle(d, lw);

@@ -400,8 +376,7 @@ const ds = approxTransit(0, lw, n);

const nadirVal = fromJulianDay(Jnoon + 0.5);
// console.log(`getSunTimes ${date.toISOString()} - Jnoon=${Jnoon} - JulianNoon=${noonVal.toISOString()} - JulianNadir=${nadirVal.toISOString()} ds=${ds}, M=${M}, L=${L}, n=${n}, d=${d}, lw=${lw}, phi=${phi}`);
const result = {
solarNoon: {
value: noonVal,
ts: noonVal.getTime(),
value: new Date(noonVal),
ts: noonVal,
name: 'solarNoon',

@@ -414,4 +389,4 @@ // elevation: 90,

nadir: {
value: nadirVal,
ts: nadirVal.getTime(),
value: new Date(nadirVal),
ts: nadirVal,
name: 'nadir',

@@ -446,4 +421,4 @@ // elevation: 270,

result[time[2]] = {
value: v1,
ts: v1.getTime(),
value: new Date(v1),
ts: v1,
name: time[2],

@@ -456,4 +431,4 @@ elevation: sa,

result[time[1]] = {
value: v2,
ts: v2.getTime(),
value: new Date(v2),
ts: v2,
name: time[1],

@@ -482,11 +457,10 @@ elevation: sa, // (180 + (sa * -1)),

* calculates sun times for a given date and latitude/longitude
* @param {Date} date Date object with the for calculating sun-times
* @param {number} dateValue date as unix timestamp for calculating sun-times
* @param {number} lat latitude for calculating sun-times
* @param {number} lng longitude for calculating sun-times
* @param {number} elevationAngle sun angle for calculating sun-time
* @param {boolean} [inUTC] defines if the calculation should be in utc or local time (default is UTC)
* @return {suntimes} result object of sunTime
*/
SunCalc.getSunTime = function (date, lat, lng, elevationAngle, inUTC) {
// console.log(`getSunTime date=${date.toISOString()} lat=${lat}, lng=${lng}, inUTC=${inUTC}, elevationAngle=${elevationAngle}`);
***
SunCalc.getSunTime = function (dateValue, lat, lng, elevationAngle) {
// console.log(`getSunTime dateValue=${dateValue} lat=${lat}, lng=${lng}, elevationAngle=${elevationAngle}`);
if (isNaN(lat)) {

@@ -503,3 +477,3 @@ throw new Error('latitude missing');

const phi = rad * lat;
const d = toDays(date, inUTC);
const d = toDays(dateValue);
const n = julianCycle(d, lw);

@@ -519,4 +493,4 @@ const ds = approxTransit(0, lw, n);

set: {
value: v1,
ts: v1.getTime(),
value: new Date(v1),
ts: v1,
elevation: elevationAngle,

@@ -526,4 +500,4 @@ julian: Jset

rise: {
value: v2,
ts: v2.getTime(),
value: new Date(v2),
ts: v2,
elevation: elevationAngle, // (180 + (elevationAngle * -1)),

@@ -533,3 +507,3 @@ julian: Jrise

};
};
}; /* **** */

@@ -567,10 +541,9 @@ // moon calculations, based on http://aa.quae.nl/en/reken/hemelpositie.html formulas

* calculates moon position for a given date and latitude/longitude
* @param {Date} date Date object with the for calculating moon-position
* @param {number} dateValue date as unix timestamp for calculating moon-position
* @param {number} lat latitude for calculating moon-position
* @param {number} lng longitude for calculating moon-position
* @param {boolean} [inUTC] defines if the calculation should be in utc or local time (default is UTC)
* @return {moonposition} result object of moon-position
*/
SunCalc.getMoonPosition = function (date, lat, lng, inUTC) {
// console.log(`getMoonPosition date=${date.toISOString()} lat=${lat}, lng=${lng}, inUTC=${inUTC}`);
SunCalc.getMoonPosition = function (dateValue, lat, lng) {
// console.log(`getMoonPosition dateValue=${dateValue} lat=${lat}, lng=${lng}`);
if (isNaN(lat)) {

@@ -585,3 +558,3 @@ throw new Error('latitude missing');

const phi = rad * lat;
const d = toDays(date, inUTC);
const d = toDays(dateValue);
const c = moonCoords(d);

@@ -619,9 +592,8 @@ const H = siderealTime(d, lw) - c.ra;

* Chapter 48 of "Astronomical Algorithms" 2nd edition by Jean Meeus (Willmann-Bell, Richmond) 1998.
* @param {Date} date Date object with the for calculating moon-illumination
* @param {boolean} [inUTC] defines if the calculation should be in utc or local time (default is UTC)
* @param {number} dateValue date as unix timestamp for calculating moon-illumination
* @return {moonillumination} result object of moon-illumination
*/
SunCalc.getMoonIllumination = function (date, inUTC) {
// console.log(`getMoonIllumination date=${date.toISOString()}`);
const d = toDays(date, inUTC);
SunCalc.getMoonIllumination = function (dateValue) {
// console.log(`getMoonIllumination dateValue=${dateValue}`);
const d = toDays(dateValue);
const s = sunCoords(d);

@@ -644,8 +616,8 @@ const m = moonCoords(d);

* add hours to a date
* @param {date} date - date object to add hours
* @param {number} dateValue date as unix timestamp to add hours
* @param {number} h - hours to add
* @returns {Date} new Date with added hours
* @returns {number} new Date as unix timestamp with added hours
*/
function hoursLater(date, h) {
return new Date(date.valueOf() + h * dayMs / 24);
function hoursLater(dateValue, h) {
return dateValue + h * dayMs / 24;
}

@@ -657,4 +629,4 @@

* @property {Date} set - a Date object if the moon is setting on the given Date, otherwhise NaN
* @property {boolean} [alwaysUp] - is true if the moon in always up, oitherwise property not exists
* @property {boolean} [alwaysDown] - is true if the moon in always up, oitherwise property not exists
* @property {boolean} alwaysUp - is true if the moon in always up, oitherwise property not exists
* @property {boolean} alwaysDown - is true if the moon in always up, oitherwise property not exists
*/

@@ -664,9 +636,8 @@

* calculations for moon rise/set times are based on http://www.stargazing.net/kepler/moonrise.html article
* @param {Date} date Date object with the for calculating moon-times
* @param {number} dateValue date as unix timestamp for calculating moon-times
* @param {number} lat latitude for calculating moon-times
* @param {number} lng longitude for calculating moon-times
* @param {boolean} [inUTC] defines if the calculation should be in utc or local time (default is UTC)
* @return {moontimes} result object of sunTime
*/
SunCalc.getMoonTimes = function (date, lat, lng, inUTC) {
SunCalc.getMoonTimes = function (dateValue, lat, lng) {
if (isNaN(lat)) {

@@ -678,17 +649,6 @@ throw new Error('latitude missing');

}
if (!isValidDate(date)) {
console.log(`getMoonTimes: given date parameter is invalid!! date=${date}`); // eslint-disable-line no-console
date = new Date();
}
// console.log(`getMoonTimes lat=${lat} lng=${lng} dateValue=${dateValue} t=${t}`);
const t = new Date(date);
if (inUTC === false) {
t.setHours(0, 0, 0, 0);
} else {
t.setUTCHours(0, 0, 0, 0);
}
// console.log(`getMoonTimes lat=${lat} lng=${lng} inUTC=${inUTC} date=${date} t=${t}`);
const hc = 0.133 * rad;
let h0 = SunCalc.getMoonPosition(t, lat, lng).altitude - hc;
let h0 = SunCalc.getMoonPosition(dateValue, lat, lng).altitude - hc;
let rise; let set; let ye; let d; let roots; let x1; let x2; let dx;

@@ -698,4 +658,4 @@

for (let i = 1; i <= 26; i += 2) {
const h1 = SunCalc.getMoonPosition(hoursLater(t, i), lat, lng).altitude - hc;
const h2 = SunCalc.getMoonPosition(hoursLater(t, i + 1), lat, lng).altitude - hc;
const h1 = SunCalc.getMoonPosition(hoursLater(dateValue, i), lat, lng).altitude - hc;
const h2 = SunCalc.getMoonPosition(hoursLater(dateValue, i + 1), lat, lng).altitude - hc;

@@ -746,3 +706,3 @@ const a = (h0 + h2) / 2 - h1;

if (rise) {
result.rise = hoursLater(t, rise);
result.rise = new Date(hoursLater(dateValue, rise));
} else {

@@ -753,3 +713,3 @@ result.rise = NaN;

if (set) {
result.set = hoursLater(t, set);
result.set = new Date(hoursLater(dateValue, set));
} else {

@@ -760,3 +720,12 @@ result.set = NaN;

if (!rise && !set) {
result[ye > 0 ? 'alwaysUp' : 'alwaysDown'] = true;
if (ye > 0) {
result.alwaysUp = true;
result.alwaysDown = false;
} else {
result.alwaysUp = false;
result.alwaysDown = true;
}
} else {
result.alwaysUp = false;
result.alwaysDown = false;
}

@@ -763,0 +732,0 @@ return result;

@@ -171,3 +171,4 @@ {

"ruleMin": "__org__ (__level__ is below minimum) [__number__] __name__",
"ruleMax": "__org__ (__level__ is above maximum) [__number__] __name__"
"ruleMax": "__org__ (__level__ is above maximum) [__number__] __name__",
"startDelay": "node in startup"
},

@@ -193,3 +194,4 @@ "states": {

"ruleMin": "__org__ [min rule __number__]",
"ruleMax": "__org__ [max rule __number__]"
"ruleMax": "__org__ [max rule __number__]",
"startDelay": "startup"
},

@@ -196,0 +198,0 @@ "errors": {

@@ -98,3 +98,4 @@ {

"ruleMin": "__org__ (__level__ is below minimum) [__number__] __name__",
"ruleMax": "__org__ (__level__ is above maximum) [__number__] __name__"
"ruleMax": "__org__ (__level__ is above maximum) [__number__] __name__",
"startDelay": "node in startup"
},

@@ -110,3 +111,4 @@ "states": {

"ruleMin": "__org__ [min rule __number__]",
"ruleMax": "__org__ [max rule __number__]"
"ruleMax": "__org__ [max rule __number__]",
"startDelay": "startup"
},

@@ -113,0 +115,0 @@ "errors": {

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

if (!this.positionConfig) {
// node.error(RED._('node-red-contrib-sun-position/position-config:errors.pos-config'));
node.status({

@@ -38,0 +37,0 @@ fill: 'red',

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

if (!this.positionConfig) {
// node.error(RED._('node-red-contrib-sun-position/position-config:errors.pos-config'));
node.status({

@@ -47,0 +46,0 @@ fill: 'red',

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

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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