Skip to content

Commit

Permalink
控制log
Browse files Browse the repository at this point in the history
  • Loading branch information
赵五一 authored and 赵五一 committed Apr 2, 2020
1 parent 3164ffc commit 13c61a3
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const serverMQTTClientPrefix = "/homebridge-mi-aqara";

var PlatformAccessory, Accessory, Service, Characteristic, UUIDGen;

var logOnce = runOnce((e) => { console.log(e) });

module.exports = function(homebridge) {
PlatformAccessory = homebridge.platformAccessory;
Accessory = homebridge.hap.Accessory;
Expand Down Expand Up @@ -433,7 +435,7 @@ MiAqaraPlatform.prototype.parseMessage = function(msg, rinfo) {
jsonObj['sid'] = "0" + jsonObj['sid'];
}

console.log('sid_zwy: ' + jsonObj['sid']);
logOnce('sid_zwy: ' + jsonObj['sid']);

// send mqtt message
if(that.mqttClient) {
Expand Down Expand Up @@ -869,3 +871,18 @@ MiAqaraPlatform.prototype.unregisterPlatformAccessories = function(accessories)
that.AccessoryUtil.remove(accessory.UUID);
});
}


function runOnce(fn, context) { //控制让函数只触发一次
return function () {
try {
fn.apply(context || this, arguments);
}
catch (e) {
// console.error(e);//一般可以注释掉这行
}
finally {
fn = null;
}
}
}

0 comments on commit 13c61a3

Please sign in to comment.