Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.0-alpha-6 to 1.0.0-alpha-7

54

nodes/clock-timer.js

@@ -195,4 +195,4 @@ /********************************************

let priook = false;
const prioMustEqual = hlp.getMsgBoolValue(msg, ['exactPriority', 'exactPrivilege']);
const prio = hlp.getMsgNumberValue(msg, ['prio', 'priority', 'privilege'], null, p => {
const prioMustEqual = hlp.getMsgBoolValue2(msg, ['exactPriority', 'exactPrivilege']);
const prio = hlp.getMsgNumberValue2(msg, ['prio', 'priority', 'privilege'], null, p => {
if (prioMustEqual) {

@@ -443,2 +443,4 @@ priook = (node.timeClockData.overwrite.priority === p);

const dayNr = now.getDay();
const dateNr = now.getDate();
const monthNr = now.getMonth();
const dayId = hlp.getDayId(now);

@@ -467,2 +469,13 @@ prepareRules(node, msg, tempData);

}
if (rule.timeMonths && rule.timeMonths !== '*' && !rule.timeMonths.includes(monthNr)) {
return null;
}
if (rule.timeBanOddDays && (dateNr % 2 !== 0)) {
// odd
return null;
}
if (rule.timeBanEvenDays && (dateNr % 2 === 0)) {
// even
return null;
}
const num = getRuleTimeData(node, msg, rule, now);

@@ -652,3 +665,3 @@ // node.debug(`pos=${rule.pos} type=${rule.timeOpText} - ${rule.timeValue} - rule.timeData = ${ util.inspect(rule.timeData, { colors: true, compact: 40, breakLength: Infinity }) }`);

*/
function setState(timeCtrl) {
function setState(pLoad) {
const code = node.reason.code;

@@ -667,6 +680,6 @@ const shape = 'ring';

node.reason.stateComplete = node.reason.state ;
if (timeCtrl.payloadOut === null || typeof timeCtrl.payloadOut !== 'object') {
node.reason.stateComplete = hlp.clipStrLength(''+timeCtrl.payloadOut,20) + ' - ' + node.reason.stateComplete;
} else if (typeof timeCtrl.payloadOut === 'object') {
node.reason.stateComplete = hlp.clipStrLength(JSON.stringify(timeCtrl.payloadOut),20) + ' - ' + node.reason.stateComplete;
if (pLoad === null || typeof pLoad !== 'object') {
node.reason.stateComplete = hlp.clipStrLength(''+pLoad,20) + ' - ' + node.reason.stateComplete;
} else if (typeof pLoad === 'object') {
node.reason.stateComplete = hlp.clipStrLength(JSON.stringify(pLoad),20) + ' - ' + node.reason.stateComplete;
}

@@ -702,7 +715,2 @@ node.status({

node.nowarn = {};
const timeCtrl = {
reason : node.reason,
timeClock: node.timeClockData,
payloadOut: node.payload.current
};
const tempData = node.context().get('cacheData',node.storeName) || {};

@@ -721,4 +729,4 @@ const previousData = node.context().get('previous',node.storeName) || {};

// check if the message contains any oversteering data
let ruleId = -1;
let ruleId = -2;
const timeCtrl = {};
// node.debug(`start pos=${node.payload.current} manual=${node.timeClockData.overwrite.active} reasoncode=${node.reason.code} description=${node.reason.description}`);

@@ -733,3 +741,5 @@ // check for manual overwrite

node.debug(`result manual=${node.timeClockData.overwrite.active} reasoncode=${node.reason.code} description=${node.reason.description}`);
setState(timeCtrl);
timeCtrl.reason = node.reason;
timeCtrl.timeClock = node.timeClockData;
setState(node.payload.current);

@@ -756,4 +766,5 @@ let topic = node.payload.topic;

msg.topic = topic;
msg.timeCtrl = timeCtrl;
if (node.outputs > 1) {
send([msg, { topic, payload: timeCtrl }]); // node.send([msg, { topic, payload: timeCtrl }]);
send([msg, { topic, payload: timeCtrl, payloadOut: node.payload.current }]); // node.send([msg, { topic, payload: timeCtrl }]);
} else {

@@ -886,2 +897,13 @@ msg.timeCtrl = timeCtrl;

if (!rule.timeDays || rule.timeDays === '*') {
rule.timeDays = null;
} else {
rule.timeDays = rule.timeDays.split(',');
}
if (!rule.timeMonths || rule.timeMonths === '*') {
rule.timeMonths = null;
} else {
rule.timeMonths = rule.timeMonths.split(',');
}
if (!rule.timeLimited) {

@@ -888,0 +910,0 @@ rule.timeOp = cRuleNoTime;

@@ -24,2 +24,3 @@ {

"ruleTimeDays": "nur an folgenden Tagen",
"ruleTimeMonths": "nur an folgenden Monaten",
"ruleDescription": "Beschreibung",

@@ -60,3 +61,4 @@ "rulePayload": "Payload:",

"level": "Behanghöhe",
"ruleTimeDays": "wähle tage an denen diese Regel gültig sein soll",
"ruleTimeDays": "wähle Tage an denen diese Regel gültig sein soll",
"ruleTimeMonths": "wähle Monate an denen diese Regel gültig sein soll",
"autoTrigger":"automatisches triggern der Neuberechnung der Rollladenposition nach einer dynamischen Zeitspanne"

@@ -63,0 +65,0 @@ },

@@ -229,3 +229,3 @@ {

],
"month": [
"months": [
"Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember",

@@ -232,0 +232,0 @@ "Jan", "Feb", "März", "Apr", "Mai", "Jun", "Jul", "Aug", "Sept", "Okt", "Nov", "Dez"

@@ -31,2 +31,3 @@ {

"ruleTimeDays":"only on day",
"ruleTimeMonths":"only on month",
"ruleDescription": "Description",

@@ -71,3 +72,10 @@ "ruleBlindLevel": "blind position",

"autoTrigger":"auto trigger",
"autoTrigger2":"recalculate every x minutes"
"autoTrigger2":"recalculate every x minutes",
"validForDays":"valid days",
"validForMonths":"valid months",
"banDays":"ban days",
"banEvenDays":"even",
"banOddDays":"odd",
"onlyEvenDays":"only even days",
"onlyOddDays":"only odd days"
},

@@ -105,2 +113,3 @@ "placeholder": {

"ruleTimeDays": "select days wherefore it should be valid",
"ruleTimeMonths": "select months wherefore it should be valid",
"autoTrigger":"automatic triggers new calculation of the blind position in a dynamic changing time interval"

@@ -107,0 +116,0 @@ },

@@ -24,2 +24,3 @@ {

"ruleTimeDays":"only on day",
"ruleTimeMonths": "only on month",
"ruleDescription": "Description",

@@ -43,3 +44,10 @@ "rulePayload": "Payload:",

"autoTrigger":"auto trigger",
"autoTrigger2":"recalculate every x minutes"
"autoTrigger2":"recalculate every x minutes",
"validForDays":"valid days",
"validForMonths":"valid months",
"banDays":"ban days",
"banEvenDays":"even",
"banOddDays":"odd",
"onlyEvenDays":"only even days",
"onlyOddDays":"only odd days"
},

@@ -62,2 +70,3 @@ "placeholder": {

"ruleTimeDays": "select days wherefore it should be valid",
"ruleTimeMonths": "select months wherefore it should be valid",
"autoTrigger":"automatic triggers new calculation of the rule in a dynamic changing time interval"

@@ -64,0 +73,0 @@ },

@@ -236,3 +236,3 @@ {

],
"month": [
"months": [
"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December",

@@ -239,0 +239,0 @@ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"

@@ -32,6 +32,13 @@ {

"hours": "hours",
"on": "on",
"on":"on",
"once": "additional",
"onstart": "Inject on start ",
"onceDelay": "seconds"
"onceDelay": "seconds",
"validForDays":"valid days",
"validForMonths":"valid months",
"banDays":"ban days",
"banEvenDays":"even",
"banOddDays":"odd",
"fewDays": "few days",
"fewMonths": "few months"
},

@@ -50,2 +57,3 @@ "placeholder": {

"days":"select days wherefore it should be valid",
"months":"select months wherefore it should be valid",
"addPayload": "allow to add additional property to the send message",

@@ -52,0 +60,0 @@ "addPayloadValue": "value of the additional property",

@@ -33,3 +33,8 @@ {

"msgvalue":"msg.value",
"showEnhSettings":"Enhanced settings"
"showEnhSettings":"Enhanced settings",
"validForDays":"valid days",
"validForMonths":"valid months",
"banDays":"ban days",
"banEvenDays":"even",
"banOddDays":"odd"
},

@@ -57,5 +62,9 @@ "placeholder": {

"invalid-propertyStart-type": "Invalid Property Type for alternate start: __type__",
"invalid-propertyEnd-type": "Invalid Property Type for alternate end: __type__"
"invalid-propertyEnd-type": "Invalid Property Type for alternate end: __type__",
"invalid-day": "Day is not selected.",
"invalid-month": "Month is not selected.",
"banned-odd-day": "Not an even Day!",
"banned-even-day": "Not an odd Day!"
}
}
}

@@ -725,3 +725,3 @@ /************************************************************************/

*/
function initDaysCheckbox(element, val) { // eslint-disable-line no-unused-vars
function initCheckboxesBlock(element, val) { // eslint-disable-line no-unused-vars
if (val === '*' || typeof val === 'undefined' || val === null) {

@@ -939,2 +939,3 @@ $(element + ' input[type=checkbox]').prop('checked', true);

* @property {string} [days] - allowed days identifier
* @property {string} [months] - allowed months identifier
* @property {string} [format] - output format

@@ -968,2 +969,6 @@ */

res = 'msg.value';
} else if (data.timeDays === '') {
res = 'No valid days given! Please check settings!';
} else if (data.timeMonths === '') {
res = 'No valid month given! Please check settings!';
} else {

@@ -1019,9 +1024,10 @@ const url = 'sun-position/data?' + jQuery.param( data );

* @param {jQuery} value - the checkbox array
* * @param {number} max - the maximum count of elements
* @returns {string} the value of the checkboxes
*/
function getDaysStr(value) { // eslint-disable-line no-unused-vars
function getCheckboxesStr(value, max) { // eslint-disable-line no-unused-vars
const days = value.map((_, el) => { return $(el).val(); }).get();
if (days.length === 0) { return ''; }
if (days.length === 7) { return '*'; }
if (days.length === max) { return '*'; }
return days.join(',');
}

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

} else {
// resultObj = node.positionConfig.getOutDataProp(node, msg, config.result1ValueType, config.result1Value, config.result1Format, config.result1Offset, config.result1OffsetType, config.result1Multiplier, true);
resultObj = node.positionConfig.getOutDataProp(node, msg, {

@@ -63,0 +62,0 @@ type: config.result1ValueType,

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

if (data.outType !== 'none') {
// const res = node.positionConfig.getOutDataProp(node, msg, valueType, value, format, offset, offsetType, multiplier, next, days);
const res = node.positionConfig.getOutDataProp(node, msg, data);

@@ -93,3 +92,26 @@ if (res === null || (typeof res === 'undefined')) {

this.timeDays = config.timeDays;
this.timeBanOddDays = config.timeBanOddDays;
this.timeBanEvenDays = config.timeBanEvenDays;
this.timeMonths = config.timeMonths;
this.timeAltDays = config.timeAltDays;
this.timeAltBanOddDays = config.timeAltBanOddDays;
this.timeAltBanEvenDays = config.timeAltBanEvenDays;
this.timeAltMonths = config.timeAltMonths;
if (this.timeDays === '') {
throw new Error('No valid days given! Please check settings!');
}
if (this.timeAltDays === '') {
throw new Error('No valid alternate days given! Please check settings!');
}
if (this.timeMonths === '') {
throw new Error('No valid month given! Please check settings!');
}
if (this.timeAltMonths === '') {
throw new Error('No valid alternate month given! Please check settings!');
}
if (this.timeAltBanEvenDays && this.timeAltBanOddDays) {
throw new Error('No valid days aviable (odd and enven days banned! Please check settings!');
}
this.offset = config.offset || config.timeOffset || 0;

@@ -141,3 +163,2 @@ this.offsetType = config.offsetType;

if (node.timeType !== 'none' && node.positionConfig) {
// node.nextTimeData = node.positionConfig.getTimeProp(node, undefined, node.timeType, node.time, node.offsetType, node.offset, node.offsetMultiplier, true, node.timeDays);
node.nextTimeData = node.positionConfig.getTimeProp(node, undefined, {

@@ -150,3 +171,6 @@ type: node.timeType,

next : true,
days : node.timeDays
days : node.timeDays,
months : node.timeMonths,
banOddDays: node.timeBanOddDays,
banEvenDays: node.timeBanEvenDays
});

@@ -171,4 +195,2 @@ if (node.nextTimeData.error) {

node.positionConfig) {
// (_srcNode, msg, vType, value, offset, offsetType, multiplier, next, days)
// node.nextTimeAltData = node.positionConfig.getTimeProp(node, undefined, node.timeAltType, node.timeAlt, node.timeAltOffsetType, node.timeAltOffset, node.timeAltOffsetMultiplier, true, node.timeAltDays);
node.nextTimeAltData = node.positionConfig.getTimeProp(node, undefined, {

@@ -181,3 +203,6 @@ type: node.timeAltType,

next : true,
days : node.timeAltDays
days : node.timeAltDays,
months : node.timeAltMonths,
banOddDays: node.timeAltBanOddDays,
banEvenDays: node.timeAltBanEvenDays
});

@@ -334,3 +359,2 @@

}
// const value = node.positionConfig.getOutDataProp(node, msg, config.payloadType, config.payload, config.payloadTimeFormat, node.payloadOffset, config.payloadOffsetType, config.payloadOffsetMultiplier, true);
const value = node.positionConfig.getOutDataProp(node, msg, {

@@ -337,0 +361,0 @@ type: config.payloadType,

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

} else {
// resultObj = node.positionConfig.getOutDataProp(node, msg, config.result1ValueType, config.result1Value, config.result1Format, config.result1Offset, config.result1OffsetType, config.result1Multiplier, true);
resultObj = node.positionConfig.getOutDataProp(node, msg, {

@@ -354,4 +353,2 @@ type: config.result1ValueType,

// node.debug('resultObj=' + util.inspect(resultObj, { colors: true, compact: 10, breakLength: Infinity }));
// to
if (resultObj === null || typeof resultObj === 'undefined') {

@@ -358,0 +355,0 @@ throw new Error('could not evaluate ' + config.result1ValueType + '.' + config.result1Value);

@@ -68,2 +68,10 @@ /********************************************

}
if (data.warn) {
node.status({
fill: 'yellow',
shape: 'dot',
text: data.warn
});
return false;
}
if (data.start && data.start.error) {

@@ -93,3 +101,3 @@ if (_onInit === true) {

node.status({
fill: 'yellow',
fill: 'blue',
shape: 'dot',

@@ -109,3 +117,3 @@ text: '⏵' + node.positionConfig.toTimeString(data.start.value) + data.startSuffix + ' - ⏴' + node.positionConfig.toTimeString(data.end.value) + data.endSuffix

*/
function calcWithinTimes(node, msg, config) {
function calcWithinTimes(node, msg, config, now) {
// node.debug('calcWithinTimes');

@@ -118,5 +126,27 @@ const result = {

altStartTime: (node.propertyStartType !== 'none') && (msg || (node.propertyStartType !== 'msg')),
altEndTime: (node.propertyEndType !== 'none') && (msg || (node.propertyEndType !== 'msg'))
altEndTime: (node.propertyEndType !== 'none') && (msg || (node.propertyEndType !== 'msg')),
valid:false
};
if (config.timeDays && config.timeDays !== '*' && !config.timeDays.includes(now.getDay())) {
node.debug('invalid Day config. today=' + now.getDay() + ' timeDays=' + util.inspect(config.timeDays, Object.getOwnPropertyNames(config.timeDays)));
result.warn = RED._('within-time-switch.errors.invalid-day');
return result;
}
if (config.timeMonths && config.timeMonths !== '*' && !config.timeMonths.includes(now.getMonth())) {
node.debug('invalid Day config. today=' + now.getMonth() + ' timeMonths=' + util.inspect(config.timeMonths, Object.getOwnPropertyNames(config.timeMonths)));
result.warn = RED._('within-time-switch.errors.invalid-month');
return result;
}
const dateNr = now.getDate();
if (config.timeBanOddDays && (dateNr % 2 !== 0)) {
result.warn = RED._('within-time-switch.errors.banned-odd-day');
return result;
}
if (config.timeBanEvenDays && (dateNr % 2 === 0)) {
result.warn = RED._('within-time-switch.errors.banned-even-day');
return result;
}
result.valid = true;
if (result.altStartTime) {

@@ -266,2 +296,13 @@ // node.debug('alternate start times enabled ' + node.propertyStartType + '.' + node.propertyStart);

this.propertyEndThresholdType = config.propertyEndThresholdType;
if (config.timeDays === '') {
throw new Error('No valid days given! Please check settings!');
}
if (config.timeMonths === '') {
throw new Error('No valid month given! Please check settings!');
}
if (config.timeAltBanEvenDays && config.timeAltBanOddDays) {
throw new Error('No valid days aviable (odd and enven days banned! Please check settings!');
}
this.timeOutObj = null;

@@ -271,2 +312,3 @@ this.lastMsgObj = null;

this.on('input', function (msg, send, done) { // eslint-disable-line complexity

@@ -286,16 +328,20 @@ // If this is pre-1.0, 'done' will be undefined

// this.debug('config ' + util.inspect(config, { colors: true, compact: 10, breakLength: Infinity }));
const result = calcWithinTimes(this, msg, config);
const now = getDate(config.tsCompare, msg, node);
const result = calcWithinTimes(this, msg, config, now);
if (!result.start.value || !result.end.value) {
throw new Error('Error can not calc time!');
}
const startNr = hlp.getTimeNumberUTC(result.start.value);
const endNr = hlp.getTimeNumberUTC(result.end.value);
const cmpNow = hlp.getTimeNumberUTC(now);
setstate(this, result);
if (startNr < endNr) {
if (cmpNow >= startNr && cmpNow < endNr) {
this.debug('in time [1] - send msg to first output ' + result.startSuffix + node.positionConfig.toDateTimeString(now) + result.endSuffix + ' (' + startNr + ' - ' + cmpNow + ' - ' + endNr + ')');
if (result.start.value && result.end.value) {
const startNr = hlp.getTimeNumberUTC(result.start.value);
const endNr = hlp.getTimeNumberUTC(result.end.value);
const cmpNow = hlp.getTimeNumberUTC(now);
setstate(this, result);
if (startNr < endNr) {
if (cmpNow >= startNr && cmpNow < endNr) {
this.debug('in time [1] - send msg to first output ' + result.startSuffix + node.positionConfig.toDateTimeString(now) + result.endSuffix + ' (' + startNr + ' - ' + cmpNow + ' - ' + endNr + ')');
send([msg, null]); // this.send([msg, null]);
checkReSendMsgDelayed(config.lastMsgOnEndOut, this, result.end.value, msg);
done();
return null;
}
} else if (!(cmpNow >= endNr && cmpNow < startNr)) {
this.debug('in time [2] - send msg to first output ' + result.startSuffix + node.positionConfig.toDateTimeString(now) + result.endSuffix + ' (' + startNr + ' - ' + cmpNow + ' - ' + endNr + ')');
send([msg, null]); // this.send([msg, null]);

@@ -306,11 +352,9 @@ checkReSendMsgDelayed(config.lastMsgOnEndOut, this, result.end.value, msg);

}
} else if (!(cmpNow >= endNr && cmpNow < startNr)) {
this.debug('in time [2] - send msg to first output ' + result.startSuffix + node.positionConfig.toDateTimeString(now) + result.endSuffix + ' (' + startNr + ' - ' + cmpNow + ' - ' + endNr + ')');
send([msg, null]); // this.send([msg, null]);
checkReSendMsgDelayed(config.lastMsgOnEndOut, this, result.end.value, msg);
done();
return null;
} else if (!result.valid) {
throw new Error('Error can not calc time!');
} else {
setstate(node, result);
}
this.debug('out of time - send msg to second output ' + result.startSuffix + node.positionConfig.toDateTimeString(now) + result.endSuffix + ' (' + startNr + ' - ' + cmpNow + ' - ' + endNr + ')');
this.debug('out of time - send msg to second output ' + result.startSuffix + node.positionConfig.toDateTimeString(now) + result.endSuffix);
send([null, msg]); // this.send([null, msg]);

@@ -336,3 +380,3 @@ checkReSendMsgDelayed(config.lastMsgOnStartOut, this, result.start.value, msg);

node.status({});
const result = calcWithinTimes(this, null, config);
const result = calcWithinTimes(this, null, config, new Date());
// if an error occurred, will retry in 6 minutes. This will prevent errors on initialization.

@@ -343,3 +387,3 @@ if (setstate(this, result, true)) {

try {
const result = calcWithinTimes(this, null, config);
const result = calcWithinTimes(this, null, config, new Date());
setstate(this, result);

@@ -346,0 +390,0 @@ } catch (err) {

{
"name": "node-red-contrib-sun-position",
"version": "1.0.0-alpha-6",
"version": "1.0.0-alpha-7",
"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 not supported yet

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

Sorry, the diff of this file is not supported yet

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