2
0

feat(battery): compute battery level by default

This commit is contained in:
Pierre CLEMENT
2018-01-01 04:39:30 +01:00
parent 33084b0220
commit 9da0427164
6 changed files with 4 additions and 5 deletions

View File

@@ -18,5 +18,4 @@ module.exports = function(RED) {
}
RED.nodes.registerType("xiaomi-all", XiaomiAllNode);
}

View File

@@ -1,6 +1,7 @@
module.exports = function(RED) {
"use strict";
var dgram = require('dgram');
var miDevicesUtils = require('../utils');
var udpInputPortsInUse = {};
function XiaomiGatewayNode(config) {
@@ -60,6 +61,9 @@ module.exports = function(RED) {
var jsonMsg = JSON.parse(msg);
if(jsonMsg.data) {
jsonMsg.data = JSON.parse(jsonMsg.data) || jsonMsg.data;
if(jsonMsg.data.voltage) {
jsonMsg.data.batteryLevel = miDevicesUtils.computeBatteryLevel(jsonMsg.data.voltage);
}
}
msg = { payload: jsonMsg };
if(jsonMsg.token && node.gateway && jsonMsg.data.ip && jsonMsg.data.ip === node.gateway.ip) {

View File

@@ -28,7 +28,6 @@ module.exports = function(RED) {
miDevicesUtils.setStatus(node, data);
if (node.output == "0") {
miDevicesUtils.prepareFullDataOutput(payload);
node.send([msg]);
} else if (node.output == "1") {
var temp = null;

View File

@@ -36,7 +36,6 @@ module.exports = function(RED) {
if (node.output == "0") {
miDevicesUtils.prepareFullDataOutput(payload);
node.send([msg]);
} else if (node.output == "1") {
var status = null;

View File

@@ -36,7 +36,6 @@ module.exports = function(RED) {
if (node.output == "0") {
miDevicesUtils.prepareFullDataOutput(payload);
node.send([msg]);
} else if (node.output == "1") {
var status = null;

View File

@@ -26,7 +26,6 @@ module.exports = function(RED) {
miDevicesUtils.setStatus(node, data);
if (node.output == "0") {
miDevicesUtils.prepareFullDataOutput(payload);
node.send([msg]);
} else if (node.output == "1") {
var status = null;