-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_helper.js
39 lines (34 loc) · 1.33 KB
/
node_helper.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
const connector = require('./js/TimeTreeConnector');
const NodeHelper = require("node_helper");
const Log = require("logger");
module.exports = NodeHelper.create({
client: undefined,
start: function () {
Log.log('Starting node helper for MMM-TimeTree');
this.client = undefined;
},
connect: function(accessToken, timezone) {
this.client = connector.connect(accessToken, timezone);
this.sendSocketNotification('TIME_TREE_CONNECT', {"status":"OK"});
Log.log('Sent response to notification=TIME_TREE_CONNECT');
},
refresh: function(calendar, numDays = 7) {
Log.log('Refresh calendar=' + calendar);
const self = this;
this.client.events(calendar, numDays).then(evs => {
self.sendSocketNotification('TIME_TREE_REFRESH', {"events":evs});
Log.log('Sent response to notification=TIME_TREE_REFRESH');
});
},
socketNotificationReceived: function (notification, payload) {
Log.log("Received notification=" + notification);
switch (notification) {
case 'TIME_TREE_CONNECT':
this.connect(payload.accessToken, payload.timezone);
return;
case 'TIME_TREE_REFRESH':
this.refresh(payload.calendar, payload.numDays);
return;
}
}
});