1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

add some status to suncalc (to see how it looks)

This commit is contained in:
Dave C-J 2014-05-17 18:32:13 +01:00
parent 191f4412f6
commit 9adc2b2687

View File

@ -14,10 +14,10 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var SunCalc = require('suncalc'); var SunCalc = require('suncalc');
function SunNode(n) { function SunNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.lat = n.lat; this.lat = n.lat;
this.lon = n.lon; this.lon = n.lon;
@ -42,6 +42,8 @@ function SunNode(n) {
msg = { payload:0, topic:"sun", moon:moon }; msg = { payload:0, topic:"sun", moon:moon };
if ((e1 > 0) & (e2 < 0)) { msg.payload = 1; } if ((e1 > 0) & (e2 < 0)) { msg.payload = 1; }
if (oldval == null) { oldval = msg.payload; } if (oldval == null) { oldval = msg.payload; }
if (msg.payload == 1) { node.status({fill:"yellow",shape:"dot",text:"day"},true); }
else { node.status({fill:"blue",shape:"dot",text:"night"},true); }
if (msg.payload != oldval) { if (msg.payload != oldval) {
oldval = msg.payload; oldval = msg.payload;
msg2 = msg; msg2 = msg;
@ -53,5 +55,6 @@ function SunNode(n) {
this.on("close", function() { this.on("close", function() {
clearInterval(this.tick); clearInterval(this.tick);
}); });
}
RED.nodes.registerType("sunrise",SunNode);
} }
RED.nodes.registerType("sunrise",SunNode);