mirror of
				https://github.com/node-red/node-red-nodes.git
				synced 2025-03-01 10:37:43 +00:00 
			
		
		
		
	Let suncalc node try to auto set geo location (if allowed)
This commit is contained in:
		@@ -1,5 +1,5 @@
 | 
			
		||||
<!--
 | 
			
		||||
  Copyright 2013 IBM Corp.
 | 
			
		||||
  Copyright 2013,2014 IBM Corp.
 | 
			
		||||
 | 
			
		||||
  Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
  you may not use this file except in compliance with the License.
 | 
			
		||||
@@ -67,8 +67,8 @@
 | 
			
		||||
            name: {value:""},
 | 
			
		||||
            lat: {value:"", required:true, validate:RED.validators.number()},
 | 
			
		||||
            lon: {value:"", required:true, validate:RED.validators.number()},
 | 
			
		||||
            start: {value:"", required:true},
 | 
			
		||||
            end: {value:"", required:true}
 | 
			
		||||
            start: {value:"sunrise", required:true},
 | 
			
		||||
            end: {value:"sunset", required:true}
 | 
			
		||||
        },
 | 
			
		||||
        inputs:0,
 | 
			
		||||
        outputs:2,
 | 
			
		||||
@@ -78,6 +78,16 @@
 | 
			
		||||
        },
 | 
			
		||||
        labelStyle: function() {
 | 
			
		||||
            return this.name?"node_label_italic":"";
 | 
			
		||||
        },
 | 
			
		||||
        oneditprepare: function() {
 | 
			
		||||
            if (($("#node-input-lat").val() === "") && ($("#node-input-lon").val() === "")) {
 | 
			
		||||
                if ("geolocation" in navigator) {
 | 
			
		||||
                    navigator.geolocation.getCurrentPosition(function(position) {
 | 
			
		||||
                        $("#node-input-lat").val(Number(position.coords.latitude.toFixed(5)));
 | 
			
		||||
                        $("#node-input-lon").val(Number(position.coords.longitude.toFixed(5)));
 | 
			
		||||
                    });
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    });
 | 
			
		||||
</script>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
/**
 | 
			
		||||
 * Copyright 2013 IBM Corp.
 | 
			
		||||
 * Copyright 2013,2014 IBM Corp.
 | 
			
		||||
 *
 | 
			
		||||
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
 * you may not use this file except in compliance with the License.
 | 
			
		||||
@@ -39,7 +39,7 @@ module.exports = function(RED) {
 | 
			
		||||
            var mins2 = times[node.end].getUTCMinutes();
 | 
			
		||||
            var e1 = (hour*60+mins) - (hour1*60+mins1);
 | 
			
		||||
            var e2 = (hour*60+mins) - (hour2*60+mins2);
 | 
			
		||||
            var moon = SunCalc.getMoonIllumination(now).fraction;
 | 
			
		||||
            var moon = parseInt(SunCalc.getMoonIllumination(now).fraction*100+0.5)/100;
 | 
			
		||||
            var msg = { payload:0, topic:"sun", moon:moon };
 | 
			
		||||
            if ((e1 > 0) & (e2 < 0)) { msg.payload = 1; }
 | 
			
		||||
            if (oldval == null) { oldval = msg.payload; }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
{
 | 
			
		||||
    "name"          : "node-red-node-suncalc",
 | 
			
		||||
    "version"       : "0.0.3",
 | 
			
		||||
    "version"       : "0.0.4",
 | 
			
		||||
    "description"   : "A Node-RED node to provide a signal at sunrise and sunset",
 | 
			
		||||
    "dependencies"  : {
 | 
			
		||||
        "suncalc"   : "1.5.*"
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user