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);
|
RED.nodes.registerType("xiaomi-all", XiaomiAllNode);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
module.exports = function(RED) {
|
module.exports = function(RED) {
|
||||||
"use strict";
|
"use strict";
|
||||||
var dgram = require('dgram');
|
var dgram = require('dgram');
|
||||||
|
var miDevicesUtils = require('../utils');
|
||||||
var udpInputPortsInUse = {};
|
var udpInputPortsInUse = {};
|
||||||
|
|
||||||
function XiaomiGatewayNode(config) {
|
function XiaomiGatewayNode(config) {
|
||||||
@@ -60,6 +61,9 @@ module.exports = function(RED) {
|
|||||||
var jsonMsg = JSON.parse(msg);
|
var jsonMsg = JSON.parse(msg);
|
||||||
if(jsonMsg.data) {
|
if(jsonMsg.data) {
|
||||||
jsonMsg.data = JSON.parse(jsonMsg.data) || 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 };
|
msg = { payload: jsonMsg };
|
||||||
if(jsonMsg.token && node.gateway && jsonMsg.data.ip && jsonMsg.data.ip === node.gateway.ip) {
|
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);
|
miDevicesUtils.setStatus(node, data);
|
||||||
|
|
||||||
if (node.output == "0") {
|
if (node.output == "0") {
|
||||||
miDevicesUtils.prepareFullDataOutput(payload);
|
|
||||||
node.send([msg]);
|
node.send([msg]);
|
||||||
} else if (node.output == "1") {
|
} else if (node.output == "1") {
|
||||||
var temp = null;
|
var temp = null;
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
|
|
||||||
if (node.output == "0") {
|
if (node.output == "0") {
|
||||||
miDevicesUtils.prepareFullDataOutput(payload);
|
|
||||||
node.send([msg]);
|
node.send([msg]);
|
||||||
} else if (node.output == "1") {
|
} else if (node.output == "1") {
|
||||||
var status = null;
|
var status = null;
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
|
|
||||||
if (node.output == "0") {
|
if (node.output == "0") {
|
||||||
miDevicesUtils.prepareFullDataOutput(payload);
|
|
||||||
node.send([msg]);
|
node.send([msg]);
|
||||||
} else if (node.output == "1") {
|
} else if (node.output == "1") {
|
||||||
var status = null;
|
var status = null;
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ module.exports = function(RED) {
|
|||||||
miDevicesUtils.setStatus(node, data);
|
miDevicesUtils.setStatus(node, data);
|
||||||
|
|
||||||
if (node.output == "0") {
|
if (node.output == "0") {
|
||||||
miDevicesUtils.prepareFullDataOutput(payload);
|
|
||||||
node.send([msg]);
|
node.send([msg]);
|
||||||
} else if (node.output == "1") {
|
} else if (node.output == "1") {
|
||||||
var status = null;
|
var status = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user