-
Notifications
You must be signed in to change notification settings - Fork 6
/
node_helper.js
34 lines (27 loc) · 1008 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
const bodyParser = require('body-parser');
const NodeHelper = require('node_helper'); // eslint-disable-line import/no-unresolved
module.exports = NodeHelper.create({
start() {
this._initHandler();
},
socketNotificationReceived(notificationName, payload) {
if (notificationName === 'MMM-RemoteTemperature.INIT') {
console.log(`MMM-RemoteTemperature Node helper: Init notification received from module for sensor "${payload.sensorId}".`); // eslint-disable-line no-console
}
},
_initHandler() {
this.expressApp.use(bodyParser.json());
this.expressApp.post('/remote-temperature', this._onTemperatureValueReceived.bind(this));
},
_onTemperatureValueReceived(req, res) {
const params = req.body;
const payload = {
temp: params.temp,
humidity: params.humidity,
battery: params.battery,
sensorId: params.sensorId
};
this.sendSocketNotification('MMM-RemoteTemperature.VALUE_RECEIVED', payload);
res.sendStatus(200);
}
});