-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMMM-GHIN.js
70 lines (60 loc) · 1.68 KB
/
MMM-GHIN.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
/* Magic Mirror2
* Module: GHIN
*
* By Clint Decker https://github.com/C-DECK
* MIT Licensed.
*/
Module.register('MMM-GHIN', {
handicap: 0.0,
// Default module config.
defaults: {
updateInterval: 1000 * 60,
ghinNumber: 0,
email: '',
password: ''
},
getStyles: function () {
return ['MMM-GHIN.css']
},
start: function () {
Log.info('Starting module: ' + this.name)
this.loginUser()
},
scheduleUpdate: function (delay) {
var nextLoad = this.config.updateInterval
if (typeof delay !== 'undefined' && delay >= 0) {
nextLoad = delay
}
var self = this
setInterval(function () {
self.getHandicap()
}, nextLoad)
},
getDom: function () {
var wrapper = document.createElement('div')
wrapper.innerHTML = `${this.handicap}`
wrapper.className = 'handicap-score'
// pass the created content back to MM to add to DOM.
return wrapper
},
loginUser: function () {
Log.info("Called login");
this.sendSocketNotification('LOGIN_USER', {email: this.config.email, password: this.config.password})
},
getHandicap: function () {
this.sendSocketNotification('GET_HANDICAP', this.config.ghinNumber)
},
// Subclass socketNotificationReceived received.
socketNotificationReceived: function (notification, payload) {
// Login worked and we can now make proper requests
Log.info("Main module received notification: " + notification);
if (notification === 'LOGIN_SUCCESS') {
this.getHandicap()
this.scheduleUpdate()
} else if (notification === 'HANDICAP_RESULT') {
console.log(payload)
this.handicap = payload.golfers[0].hi_value
this.updateDom()
}
},
})