-
Notifications
You must be signed in to change notification settings - Fork 1
/
node_helper.js
40 lines (32 loc) · 990 Bytes
/
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
40
"use strict";
/* Magic Mirror
* Module: MMM-max
*
* By mirko30000
* MIT Licensed.
*/
const NodeHelper = require('node_helper');
var MaxCube = require('./maxcube/maxcube');
module.exports = NodeHelper.create({
start: function () {
console.log("Starting max helper");
},
//Subclass socketNotificationReceived received.
socketNotificationReceived: function(notification, payload) {
if (notification === 'MAX_UPDATE') {
console.log("Triggering MAX upate");
var self = this;
var config = payload;
var myMaxCube = new MaxCube(config.maxIP, config.maxPort);
myMaxCube.on('connected', function () {
myMaxCube.getDeviceStatus().then(function (devices) {
for (var i = 0; i < devices.length; i++) {
devices[i].deviceInfo = myMaxCube.getDeviceInfo(devices[i].rf_address);
}
self.sendSocketNotification('MAX_DATA', devices);
myMaxCube.close();
});
});
}
}
});