This repository has been archived by the owner on Oct 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmmm-moon-phases.js
88 lines (73 loc) · 2.78 KB
/
mmm-moon-phases.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* global Log, Module */
/* MMM2 Module */
/* spectroman's
* Module: Moon Phases
*
* By Spectroman https://juliochegedus.com
* MIT Licensed.
*/
Module.register("mmm-moon-phases", {
defaults: {
updateInterval: 14400 * 1000, // every 2 hours
initialLoadDelay: 1,
retryDelay: 2500,
height: 150,
width: 150,
// delay: 0,
domain: "tycho.usno.navy.mil",
path: "/gif/phase.gif",
homeMM: "/home/pi/MagicMirror"
},
// Define required scripts.
getScripts: function() {
return ["moment.js"];
},
getDom: function() {
var wrapper = document.createElement("div");
wrapper.style.width = this.config.width + "px";
wrapper.style.height = this.config.height + "px";
wrapper.style.overflow = "hidden";
wrapper.style.position = "relative";
var img = document.createElement("img");
img.style.position = "absolute";
img.style.left = "5px";
img.style.top = "-" + Math.round(this.config.height / 10) + "px";
img.height = this.config.height;
img.width = this.config.width;
img.src = this.imgmoon;
wrapper.appendChild(img);
return wrapper;
},
// Define start sequence.
start: function() {
Log.info("Starting module: " + this.name);
this.loaded = false;
this.scheduleUpdate(this.config.initialLoadDelay);
this.updateTimer = null;
},
updateMoon: function() {
var self = this;
self.sendSocketNotification("BRING_MOON", { homeMM: this.config.homeMM, domain: this.config.domain, path: this.config.path } );
},
socketNotificationReceived: function(notification, payload) {
if(notification === "MOON"){
this.imgmoon=payload
if (typeof this.imgmoon !== "undefined") {
this.loaded=true;
this.updateDom();
};
this.scheduleUpdate();
}
},
scheduleUpdate: function(delay) {
var nextLoad = this.config.updateInterval;
if (typeof delay !== "undefined" && delay >= 0) {
nextLoad = delay;
}
var self = this;
clearTimeout(this.updateTimer);
this.updateTimer = setTimeout(function() {
self.updateMoon();
}, nextLoad);
},
});