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.4 to 0.2.5

8

nodes/lib/dateTimeHelper.js

@@ -296,2 +296,5 @@ /********************************************

function addOffset(d, offset, multiplier) {
if (d.value) { d = d.value; }
if (!(d instanceof Date)) { d = Date(d); }
if (offset && !isNaN(offset) && offset !== 0) {

@@ -764,5 +767,4 @@ if (offset !== 0 && multiplier > 0) {

format = format || 0;
if (!(date instanceof Date)) {
date = Date(date);
}
if (date.value) { date = date.value; }
if (!(date instanceof Date)) { date = Date(date); }

@@ -769,0 +771,0 @@ if (isNaN(format)) {

@@ -8,14 +8,36 @@ {

"topic" :"Topic",
"azimuthpos":"azimuth position",
"between":"between",
"and":"and",
"name": "Name"
"name": "Name",
"start": "Start",
"startOffset":"Start Offset",
"end": "End",
"endOffset":"Start Offset"
},
"placeholder": {
"position" : "Position",
"name": "Name"
"name": "Name",
"startOffset": 0,
"endOffset": 0
},
"tips": {
"sunPosControl" : "If a message arrives through the Input the calculated position of the sun will be always send to the first output. If additionally specifyd upper and lower limits for the solar radiation and the azimuth is inside the defined limits the incomming message will send to the associated output."
}
"sunPosControl" : "If a message arrives through the Input the calculated position of the sun will be always send to the first output. If additionally specified upper and lower limits for the solar radiation and the azimuth is inside the defined limits the incoming message will send to the associated output.",
"config": "This configuration is used to add a sunInSky property of the message emitted to the first output. This can be used to work with node-red-contrib-blindcontroller nodes"
},
"multiplierGroups": [
"Standard",
"Special"
],
"multiplier": [
"milliseconds",
"seconds",
"minutes",
"hours",
"days",
"weeks",
"month",
"year"
]
}
}

@@ -192,3 +192,3 @@ /********************************************

this.getOutDataProp = (_srcNode, msg, vType, value, format, offset, offsetType, multiplier, days) => {
_srcNode.debug('getOutDataProp type='+vType+' value='+value+' format='+format+' offset='+offset+' offset='+offsetType+' multiplier='+multiplier);
// _srcNode.debug('getOutDataProp type='+vType+' value='+value+' format='+format+' offset='+offset+' offset='+offsetType+' multiplier='+multiplier);
let result = null;

@@ -229,3 +229,3 @@ if (vType === null || vType === 'none' || vType === '' || (typeof vType === 'undefined')) {

if (result && result.value && !result.error) {
return node.formatOutDate(result, format);
return node.formatOutDate(result.value, format);
}

@@ -252,3 +252,3 @@ return null;

this.getDateFromProp = (_srcNode, msg, vType, value, format, offset, offsetType, multiplier) => {
_srcNode.debug('getDateFromProp type='+vType+' value='+value+' format='+format+' offset='+offset+ ' offsetType=' + offsetType +' multiplier='+multiplier);
// _srcNode.debug('getDateFromProp type='+vType+' value='+value+' format='+format+' offset='+offset+ ' offsetType=' + offsetType +' multiplier='+multiplier);
let result = null;

@@ -401,2 +401,5 @@ try {

const sunPos = sunCalc.getPosition(date, node.latitude, node.longitude);
const azimuthDegrees = 180 + 180 / Math.PI * sunPos.azimuth;
const altitudeDegrees = 180 / Math.PI * sunPos.altitude; // elevation = altitude
const result = {

@@ -408,4 +411,8 @@ ts: date.getTime(),

angleType: node.angleType,
azimuth: (node.angleType === 'deg') ? 180 + 180 / Math.PI * sunPos.azimuth : sunPos.azimuth,
altitude: (node.angleType === 'deg') ? 180 / Math.PI * sunPos.altitude : sunPos.altitude // elevation = altitude
azimuth: (node.angleType === 'deg') ? azimuthDegrees : sunPos.azimuth,
altitude: (node.angleType === 'deg') ? altitudeDegrees : sunPos.altitude, // elevation = altitude
altitudeDegrees: altitudeDegrees,
azimuthDegrees: azimuthDegrees,
altitudeRadians: sunPos.altitude,
azimuthRadians: sunPos.azimuth
};

@@ -412,0 +419,0 @@ sunTimesCheck(node);

@@ -19,2 +19,12 @@ /********************************************

this.azimuthPos = {};
this.start = config.start;
this.startType = config.startType || 'none';
this.startOffset = config.startOffset || 0;
this.startOffsetType = config.startOffsetType || 'none';
this.startOffsetMultiplier = config.startOffsetMultiplier || 60;
this.end = config.end;
this.endType = config.endType || 'none';
this.endOffset = config.endOffset || 0;
this.endOffsetType = config.endOffsetType || 'none';
this.endOffsetMultiplier = config.endOffsetMultiplier || 60;
const node = this;

@@ -24,2 +34,10 @@

try {
let 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);
}
const ports = new Array(this.rules.length);

@@ -38,2 +56,31 @@ ports[0] = {

ports[0].payload.posChanged = false;
if (node.startType !== 'none') {
const startTime = node.positionConfig.getTimeProp(node, msg, node.startType, node.start, node.startOffset, node.startOffsetType, node.startOffsetMultiplier);
node.debug('startTime: ' + util.inspect(startTime));
if (startTime.error) {
errorStatus = 'could not evaluate start time';
node.error(startTime.error);
node.debug('startTime: ' + util.inspect(startTime));
} else {
ports[0].payload.startTime = startTime.value.getTime();
}
}
if (node.endType !== 'none') {
const endTime = node.positionConfig.getTimeProp(node, msg, node.endType, node.end, node.endOffset, node.endOffsetType, node.endOffsetMultiplier);
node.debug('endTime: ' + util.inspect(endTime));
if (endTime.error) {
errorStatus = 'could not evaluate end time';
node.error(endTime.error);
node.debug('endTime: ' + util.inspect(endTime));
} else {
ports[0].payload.endTime = endTime.value.getTime();
}
}
if (ports[0].payload.startTime && ports[0].payload.endTime) {
const nowMillis = now.getTime();
ports[0].payload.sunInSky = nowMillis > ports[0].payload.startTime && nowMillis < ports[0].payload.endTime;
}
for (let i = 0; i < this.rules.length; i += 1) {

@@ -49,2 +96,4 @@ const rule = this.rules[i];

ports[i + 1] = RED.util.cloneMessage(msg);
ports[i + 1].payload.sunPos = chk;
ports[i + 1].payload.posChanged = chg;
ports[i + 1].posChanged = chg;

@@ -56,7 +105,32 @@ }

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 if (ports[0].payload.startTime && ports[0].payload.endTime) {
if (ports[0].payload.sunInSky === true) {
node.status({
fill: 'yellow',
shape: 'dot',
text: new Date(ports[0].payload.startTime).toLocaleTimeString() + ' - ' +
new Date(ports[0].payload.endTime).toLocaleTimeString()
});
} else {
node.status({
fill: 'blue',
shape: 'dot',
text: new Date(ports[0].payload.startTime).toLocaleTimeString() + ' - ' +
new Date(ports[0].payload.endTime).toLocaleTimeString()
});
}
} else {
this.status({
fill: 'grey',
shape: 'dot',
text: ports[0].payload.azimuth.toFixed(2) + '/' + ports[0].payload.altitude.toFixed(2) + ' - ' + ports[0].payload.lastUpdate.toLocaleString()
});
}
return null;

@@ -63,0 +137,0 @@ } catch (err) {

@@ -68,3 +68,4 @@ /********************************************

this.offset = config.offset || config.timeOffset || 0;
this.offsetType = config.offsetType || (this.offset === 0) ? 'none' : 'num';
this.offsetType = config.offsetType;
if (!this.offsetType) { this.offsetType = ((this.offset === 0) ? 'none' : 'num'); }
this.offsetMultiplier = config.offsetMultiplier || config.timeOffsetMultiplier || 60;

@@ -77,3 +78,4 @@

this.timeAltOffset = config.timeAltOffset || 0;
this.timeAltOffsetType = config.timeAltOffsetType || (this.timeAltOffset === 0) ? 'none' : 'num';
this.timeAltOffsetType = config.timeAltOffsetType;
if (!this.timeAltOffsetType) { this.timeAltOffsetType = ((this.timeAltOffset === 0) ? 'none' : 'num'); }
this.timeAltOffsetMultiplier = config.timeAltOffsetMultiplier || 60;

@@ -80,0 +82,0 @@

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

@@ -18,2 +18,3 @@ "keywords": [

"luminary",
"sunpos",
"suncalc",

@@ -20,0 +21,0 @@ "mooncalc",

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

The node calculates the current sun position on any input message.
The node calculates the current sun position on any input message. This node is compatible to [node-red-contrib-blindcontroller](https://github.com/alisdairjsmyth/node-red-contrib-blindcontroller).

@@ -142,2 +142,5 @@ ![sun-position](images/sun-position-example.png?raw=true)

- `msg.payload.posChanged` boolean which is true if any of the defined limit of the azimuth has changed to the last calculation.
- `msg.payload.startTime` if a start time is defined the start timestamp (inclusive of offset).
- `msg.payload.endTime` if a end time is defined the end timestamp (inclusive of offset).
- `msg.payload.sunInSky` if a start and an end time is defined a boolean value indicating whether it is currently considered daylight hours.

@@ -144,0 +147,0 @@ ```json

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