feat(battery): compute battery level by default
This commit is contained in:
@@ -18,5 +18,4 @@ module.exports = function(RED) {
|
||||
}
|
||||
|
||||
RED.nodes.registerType("xiaomi-all", XiaomiAllNode);
|
||||
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user