node-red-contrib-sun-position
Advanced tools
Comparing version 0.0.8 to 0.1.1
@@ -0,0 +0,0 @@ module.exports = { |
@@ -21,3 +21,3 @@ /******************************************** | ||
/*******************************************************************************************************/ | ||
Date.prototype.addDays = function(days) { | ||
Date.prototype.addDays = function (days) { | ||
var date = new Date(this.valueOf()); | ||
@@ -147,3 +147,3 @@ date.setUTCDate(date.getUTCDate() + days); | ||
(parseInt(matches[3]) || 0), 0); | ||
console.log(d); | ||
//console.log(d); | ||
} else { | ||
@@ -174,3 +174,3 @@ return null; | ||
function getTimeOfTextUTC(t, tzOffset, offset, next, days, date) { | ||
console.debug('getTimeOfTextUTC t=' + t + ' tzOffset=' + tzOffset + ' offset=' + offset + ' next=' + next + ' days=' + days); | ||
//console.debug('getTimeOfTextUTC t=' + t + ' tzOffset=' + tzOffset + ' offset=' + offset + ' next=' + next + ' days=' + days); | ||
let d = date || new Date(); | ||
@@ -181,5 +181,5 @@ if (t && (t.indexOf('.') === -1) && (t.indexOf('-') === -1)) { | ||
d.setHours((parseInt(matches[1]) + (matches[4] ? 12 : 0)), | ||
(parseInt(matches[2]) || 0) + (tzOffset || 0), | ||
(parseInt(matches[2]) || 0) + (tzOffset || 0), | ||
(parseInt(matches[3]) || 0), 0); | ||
console.log(d); | ||
//console.log(d); | ||
} else { | ||
@@ -186,0 +186,0 @@ return null; |
@@ -17,2 +17,8 @@ { | ||
"endOffsetAlt": "Offset", | ||
"statusOut": "Status", | ||
"statusNone": "none", | ||
"statusOnlyError": "only errors", | ||
"statusSend": "last message", | ||
"statusTime": "time limits", | ||
"statusTimeOrSend": "time limits or last message", | ||
"seconds": "seconds", | ||
@@ -19,0 +25,0 @@ "minutes": "minutes", |
@@ -17,2 +17,8 @@ { | ||
"endOffsetAlt": "Offset", | ||
"statusOut": "Status", | ||
"statusNone": "none", | ||
"statusOnlyError": "only errors", | ||
"statusSend": "last message", | ||
"statusTime": "time limits", | ||
"statusTimeOrSend": "time limits or last message", | ||
"seconds": "seconds", | ||
@@ -19,0 +25,0 @@ "minutes": "minutes", |
@@ -61,3 +61,3 @@ /******************************************** | ||
Date.prototype.addDays = function(days) { | ||
Date.prototype.addDays = function (days) { | ||
var date = new Date(this.valueOf()); | ||
@@ -86,3 +86,3 @@ date.setUTCDate(date.getUTCDate() + days); | ||
module.exports = function(RED) { | ||
module.exports = function (RED) { | ||
"use strict"; | ||
@@ -357,2 +357,14 @@ | ||
/**************************************************************************************************************/ | ||
//sendDebug({id:node.id, name:node.name, topic:msg.topic, msg:msg, _path:msg._path}); | ||
//{id:node.id, z:node.z, name:node.name, topic:msg.topic, property:property, msg:output, _path:msg._path} | ||
/* | ||
function sendDebug(msg) { | ||
// don't put blank errors in sidebar (but do add to logs) | ||
//if ((msg.msg === "") && (msg.hasOwnProperty("level")) && (msg.level === 20)) { return; } | ||
msg = RED.util.encodeObject(msg, { | ||
maxLength: debuglength | ||
}); | ||
RED.comms.publish("debug", msg); | ||
} /* */ | ||
/**************************************************************************************************************/ | ||
function sunTimesRefresh(node, today, tomorrow, dayId) { | ||
@@ -359,0 +371,0 @@ node.debug('sunTimesRefresh - calculate sun times'); |
@@ -10,3 +10,3 @@ /******************************************** | ||
module.exports = function(RED) { | ||
module.exports = function (RED) { | ||
"use strict"; | ||
@@ -181,3 +181,3 @@ | ||
this.on('close', function() { | ||
this.on('close', function () { | ||
if (node.timeOutObj) { | ||
@@ -214,8 +214,8 @@ clearTimeout(node.timeOutObj); | ||
node.send(msg); | ||
} else if (plType === "typeSunCalc") { | ||
} else if (plType === "pdsCalcData") { | ||
msg.payload = this.positionConfig.getSunCalc(msg.ts); | ||
} else if (plType === "typeMoonCalc") { | ||
} else if (plType === "pdmCalcData") { | ||
msg.payload = this.positionConfig.getMoonCalc(msg.ts); | ||
} else { | ||
RED.util.evaluateNodeProperty(plValue, plType, this, msg, function(err, res) { | ||
RED.util.evaluateNodeProperty(plValue, plType, this, msg, function (err, res) { | ||
if (err) { | ||
@@ -237,3 +237,3 @@ hlp.errorHandler(node, err, RED._("time-inject.errors.error-text"), RED._("time-inject.errors.error-title")); | ||
if (this.once) { | ||
this.onceTimeout = setTimeout(function() { | ||
this.onceTimeout = setTimeout(function () { | ||
node.emit("input", { | ||
@@ -240,0 +240,0 @@ type: 'once' |
@@ -12,2 +12,76 @@ /******************************************** | ||
function setstate(node, result, status, statusObj) { | ||
if (status > 255) { | ||
return result; | ||
} | ||
if (result.start.error) { | ||
hlp.errorHandler(node, new Error('Error get start time:' + result.start.error), RED._("within-time-switch.errors.error-text"), result.start.error); | ||
} else if (result.end.error) { | ||
hlp.errorHandler(node, new Error('Error get end time:' + result.end.error), RED._("within-time-switch.errors.error-text"), result.end.error); | ||
} else if ((status & 2) && statusObj) { | ||
node.status(statusObj); | ||
} else if ((status & 1) && result.start.value && result.end.value) { | ||
node.status({ | ||
fill: "yellow", | ||
shape: "dot", | ||
text: '⏲ ⏵' + result.start.value.toLocaleTimeString() + result.startSuffix + ' - ⏴' + result.end.value.toLocaleTimeString() + result.endSuffix | ||
}); | ||
} else { | ||
node.status({}); | ||
/*node.status({ | ||
fill: "red", | ||
shape: "dot", | ||
text: 'status not available' | ||
});*/ | ||
} | ||
} | ||
function calcWithinTimes(node, msg, config, noState) { | ||
let result = { | ||
start: {}, | ||
end: {}, | ||
startSuffix: '', | ||
endSuffix: '' | ||
} | ||
let alternateTimes = node.propertyType !== 'none'; | ||
if (alternateTimes && msg) { | ||
//node.debug('alternate times enabled ' + node.propertyType + '.' + node.property); | ||
try { | ||
//evaluateNodeProperty(node.property, type, node, msg, callback) | ||
let res = RED.util.evaluateNodeProperty(node.property, node.propertyType, node, msg); | ||
alternateTimes = ((res == true) || (res == 'true')); | ||
} catch (err) { | ||
alternateTimes = false; | ||
hlp.errorHandler(node, err, RED._("within-time-switch.errors.invalid-property-type", { | ||
type: node.propertyType, | ||
value: node.property | ||
})); | ||
node.debug(JSON.stringify(err)); | ||
} | ||
} | ||
if (alternateTimes && config.startTimeAltType !== 'none') { | ||
//node.debug('using alternate start time'); | ||
result.start = node.positionConfig.getTimeProp(node, msg, config.startTimeAltType, config.startTimeAlt, (config.startOffsetAlt || 0) * (config.startOffsetAltMultiplier || 60)); | ||
result.startSuffix = '⎇ '; | ||
} else { | ||
//node.debug('using standard start time ' + alternateTimes + ' - ' + config.startTimeAltType); | ||
result.start = node.positionConfig.getTimeProp(node, msg, config.startTimeType, config.startTime, (config.startOffset || 0) * (config.startOffsetMultiplier || 60)); | ||
} | ||
if (alternateTimes && config.endTimeAltType !== 'none') { | ||
//node.debug('using alternate end time'); | ||
result.end = node.positionConfig.getTimeProp(node, msg, config.endTimeAltType, config.endTimeAlt, (config.endOffsetAlt || 0) * (config.endOffsetAltMultiplier || 60)); | ||
result.endSuffix = ' ⎇'; | ||
} else { | ||
//node.debug('using standard end time ' + alternateTimes + ' - ' + config.startTimeAltType); | ||
result.end = node.positionConfig.getTimeProp(node, msg, config.endTimeType, config.endTime, (config.endOffset || 0) * (config.endOffsetMultiplier || 60)); | ||
} | ||
node.debug(JSON.stringify(result, Object.getOwnPropertyNames(result))); | ||
return result; | ||
} | ||
function withinTimeSwitchNode(config) { | ||
@@ -29,59 +103,5 @@ RED.nodes.createNode(this, config); | ||
let result = calcWithinTimes(this, msg, config, true); | ||
let now = new Date(); | ||
let start; | ||
let end; | ||
let alternateTimes = this.propertyType !== 'none'; | ||
if (alternateTimes) { | ||
//this.debug('alternate times enabled ' + this.propertyType + '.' + this.property); | ||
try { | ||
//evaluateNodeProperty(this.property, type, node, msg, callback) | ||
let res = RED.util.evaluateNodeProperty(this.property, this.propertyType, node, msg); | ||
alternateTimes = ((res == true) || (res == 'true')); | ||
} catch (err) { | ||
alternateTimes = false; | ||
hlp.errorHandler(node, err, RED._("within-time-switch.errors.invalid-property-type", { | ||
type: this.propertyType, | ||
value: this.property | ||
})); | ||
node.debug(JSON.stringify(err)); | ||
} | ||
} | ||
let startSuffix = ''; | ||
if (alternateTimes && config.startTimeAltType !== 'none') { | ||
//this.debug('using alternate start time'); | ||
start = node.positionConfig.getTimeProp(this, msg, config.startTimeAltType, config.startTimeAlt, (config.startOffsetAlt || 0) * (config.startOffsetAltMultiplier || 60)); | ||
startSuffix = '⎇⏴ '; | ||
} else { | ||
//this.debug('using standard start time ' + alternateTimes + ' - ' + config.startTimeAltType); | ||
start = node.positionConfig.getTimeProp(this, msg, config.startTimeType, config.startTime, (config.startOffset || 0) * (config.startOffsetMultiplier || 60)); | ||
} | ||
let endSuffix = ''; | ||
if (alternateTimes && config.endTimeAltType !== 'none') { | ||
//this.debug('using alternate end time'); | ||
end = node.positionConfig.getTimeProp(this, msg, config.endTimeAltType, config.endTimeAlt, (config.endOffsetAlt || 0) * (config.endOffsetAltMultiplier || 60)); | ||
endSuffix = ' ⏵⎇'; | ||
} else { | ||
//this.debug('using standard end time ' + alternateTimes + ' - ' + config.startTimeAltType); | ||
end = node.positionConfig.getTimeProp(this, msg, config.endTimeType, config.endTime, (config.endOffset || 0) * (config.endOffsetMultiplier || 60)); | ||
} | ||
if (start.error) { | ||
this.status({ | ||
fill: "red", | ||
shape: "dot", | ||
text: start.error | ||
}); | ||
throw new Error('Error get start time:' + start.error); | ||
} | ||
if (end.error) { | ||
this.status({ | ||
fill: "red", | ||
shape: "dot", | ||
text: start.error | ||
}); | ||
throw new Error('Error get end time:' + start.error); | ||
} | ||
if ((typeof msg.ts === 'string') || (msg.ts instanceof Date)) { | ||
@@ -93,15 +113,20 @@ let dto = new Date(msg.ts); | ||
} | ||
//this.debug(start.value + ' - ' + now + ' - ' + end.value); | ||
let startNr = hlp.getTimeNumber(start.value); | ||
let endNr = hlp.getTimeNumber(end.value); | ||
if (!result.start.value || !result.end.value) { | ||
throw new Error('Error can not calc time!'); | ||
} | ||
//this.debug(result.start.value + ' - ' + now + ' - ' + result.end.value); | ||
let startNr = hlp.getTimeNumber(result.start.value); | ||
let endNr = hlp.getTimeNumber(result.end.value); | ||
let cmpNow = hlp.getTimeNumber(now); | ||
//this.debug(startNr + ' - ' + cmpNow + ' - ' + endNr); | ||
let status = (config.statusOut || 3); | ||
if (startNr < endNr) { | ||
if (cmpNow >= startNr && cmpNow <= endNr) { | ||
this.send([msg, null]); | ||
this.status({ | ||
setstate(this, result, status, { | ||
fill: "green", | ||
shape: "dot", | ||
text: startSuffix + now.toLocaleString() + endSuffix | ||
shape: "ring", | ||
text: '🖅 ' + result.startSuffix + now.toLocaleString() + result.endSuffix //🖅 | ||
}); | ||
@@ -113,6 +138,6 @@ return null; | ||
this.send([msg, null]); | ||
this.status({ | ||
setstate(this, result, status, { | ||
fill: "green", | ||
shape: "ring", | ||
text: startSuffix + now.toLocaleString() + endSuffix | ||
shape: "dot", | ||
text: '🖅 ' + result.startSuffix + now.toLocaleString() + result.endSuffix //🖅 | ||
}); | ||
@@ -122,6 +147,6 @@ return null; | ||
} | ||
this.status({ | ||
setstate(this, result, status, { | ||
fill: "yellow", | ||
shape: "dot", | ||
text: now.toLocaleString() + startSuffix + endSuffix | ||
text: '⛔ ⏵' + result.start.value.toLocaleTimeString() + result.startSuffix + ' - ⏴' + result.end.value.toLocaleTimeString() + result.endSuffix | ||
}); | ||
@@ -133,4 +158,12 @@ this.send([null, msg]); | ||
}); | ||
try { | ||
node.status({}); | ||
let result = calcWithinTimes(this, null, config, true); | ||
setstate(this, result, (config.statusOut || 3)); | ||
} catch (err) { | ||
hlp.errorHandler(this, err, RED._("within-time-switch.errors.error-text"), RED._("within-time-switch.errors.error-title")); | ||
} | ||
} | ||
RED.nodes.registerType('within-time-switch', withinTimeSwitchNode); | ||
}; |
{ | ||
"name": "node-red-contrib-sun-position", | ||
"version": "0.0.8", | ||
"version": "0.1.1", | ||
"description": "NodeRED nodes to get sun and moon position", | ||
@@ -39,10 +39,10 @@ "main": "none", | ||
], | ||
"homepage": "https://github.com/Hypnos3/node-red-contrib-sun-position", | ||
"homepage": "https://github.com/HM-RedMatic/node-red-contrib-sun-position", | ||
"license": "Apache-2.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/Hypnos3/node-red-contrib-sun-position" | ||
"url": "https://github.com/HM-RedMatic/node-red-contrib-sun-position" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/Hypnos3/node-red-contrib-sun-position/issues" | ||
"url": "https://github.com/HM-RedMatic/node-red-contrib-sun-position/issues" | ||
}, | ||
@@ -49,0 +49,0 @@ "dependencies": { |
# node-red-contrib-sun-position for NodeRED | ||
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/hypnos3/node-red-contrib-sun-position/graphs/commit-activity) | ||
[![GitHub version](https://badge.fury.io/gh/Hypnos3%2Fnode-red-contrib-sun-position.svg)](https://github.com/hypnos3/node-red-contrib-sun-position) | ||
[![NPM version](https://badge.fury.io/js/node-red-contrib-sun-position.svg)](http://badge.fury.io/js/node-red-contrib-sun-position) | ||
[![HitCount](http://hits.dwyl.io/hypnos3/node-red-contrib-sun-position.svg)](http://hits.dwyl.io/hypnos3/node-red-contrib-sun-position) | ||
[![Dependencies Status](https://david-dm.org/hypnos3/node-red-contrib-sun-position/status.svg)](https://david-dm.org/hypnos3/node-red-contrib-sun-position) | ||
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/HM-RedMatic/node-red-contrib-sun-position/graphs/commit-activity) | ||
[![npm version](https://img.shields.io/npm/v/node-red-contrib-sun-position.svg)](https://www.npmjs.com/package/node-red-contrib-sun-position) | ||
[![HitCount](http://hits.dwyl.io/HM-RedMatic/node-red-contrib-sun-position.svg)](http://hits.dwyl.io/HM-RedMatic/node-red-contrib-sun-position) | ||
[![Dependencies Status](https://img.shields.io/david/HM-RedMatic/node-red-contrib-sun-position.svg)](https://david-dm.org/HM-RedMatic/node-red-contrib-sun-position) | ||
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) | ||
[![Issues](https://img.shields.io/github/issues/hypnos3/node-red-contrib-sun-position.svg?style=flat-square)](https://github.com/hypnos3/node-red-contrib-sun-position/issues) | ||
[![Issues](https://img.shields.io/github/issues/HM-RedMatic/node-red-contrib-sun-position.svg?style=flat-square)](https://github.com/HM-RedMatic/node-red-contrib-sun-position/issues) | ||
<!-- [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) --> | ||
@@ -279,2 +283,7 @@ | ||
- **Property** _optional_ here can be defined a context property which must be of tyxpe boolean. If this property is true alternate time will be used. | ||
- **Alternate time** _optional_ defines an alternate start time which will be used if the property is true. This can be used for different times for example of holidays/weekend. | ||
- **Additional Inject on Start** If this checkbox is set the inject node dcan emit the message on Node-Red Start or on any deploy of this node. There can be defined a delay after the emit should be done. This can be usefull for initializing any flow. | ||
#### Node Input | ||
@@ -307,2 +316,11 @@ | ||
- **Status** here can be adjusted which status should be displayed under the node. | ||
- this has the following posibilities: | ||
- **none** - no status will be displayed - **only errors** - if an error occures it will be displayed | ||
![within-time-status-error](images/within-time-status-error.png?raw=true) - **time limits** - the time limits will be displayed. An `⎇` sign after a time will show that an alternate time is used. | ||
![within-time-status-time](images/within-time-status-time.png?raw=true) - **last message** - the time limits will be shown and if the last message was blocked. An `⎇` sign after a time will show that an alternate time is used. | ||
![within-time-status-error](images/within-time-status-message-block.png?raw=true) | ||
if the message was pass throught the timestamp of this message will be shown. | ||
![within-time-status-send](images/within-time-status-message-send.png?raw=true) - **time limits or last message** - on deploy/start until a message arrives the same behaviour as `time limits` options, otherwise the `last message` status display. | ||
### Times definitions | ||
@@ -358,3 +376,3 @@ | ||
For bugs, questions and discussions please use the | ||
[GitHub Issues](https://github.com/Hypnos3/node-red-contrib-sun-position/issues). | ||
[GitHub Issues](https://github.com/HM-RedMatic/node-red-contrib-sun-position/issues). | ||
@@ -380,2 +398,2 @@ ### :moneybag: Donations [![Donate](https://img.shields.io/badge/donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4PCF5YW5ASHBN) | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/Hypnos3/node-red-contrib-sun-position.svg)](https://greenkeeper.io/) | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/HM-RedMatic/node-red-contrib-sun-position.svg)](https://greenkeeper.io/) |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
57
2306
396
568951