-
Notifications
You must be signed in to change notification settings - Fork 1
/
node_helper.js
34 lines (28 loc) · 1.19 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
const bodyParser = require('body-parser');
const NodeHelper = require('node_helper');
module.exports = NodeHelper.create({
start() {
this.expressApp.use(bodyParser.json());
this.expressApp.post('/remote-nest-thermostat', (req, res) => {
const params = req.body;
console.log(`MMM-NestRemoteThermostat Node helper: New message receive: `);
console.log(JSON.stringify(params, null, 4))
const payload = {
thermostatId: params.thermostatId,
targetTemperature: params.targetTemperature,
ambientTemperature: params.ambientTemperature,
state: params.state.toLowerCase(),
power: params.power,
icon: params.icon.toLowerCase(),
loading: typeof params.loading == "boolean" ? params.loading : params.loading == "True"
};
res.send({"status": "success", "payload": payload,});
this.sendSocketNotification('MMM-NestRemoteThermostat.VALUE_RECEIVED', payload);
});
},
socketNotificationReceived(notificationName, payload) {
if (notificationName === 'MMM-NestRemoteThermostat.INIT') {
console.log(`MMM-NestRemoteThermostat Node helper: Init notification received from module for thermostat "${payload.thermostatId}".`); // eslint-disable-line no-console
}
},
});