Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the bug that the gateway accessories cannot be found correctly when the gateway mac address starts with 0 #304

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions 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 @@ -432,6 +434,12 @@ MiAqaraPlatform.prototype.parseMessage = function(msg, rinfo) {
return;
}

if (jsonObj['sid'].length < 12) {
jsonObj['sid'] = "0" + jsonObj['sid'];
}

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

// send mqtt message
if(that.mqttClient) {
that.sendMQTTMessage4ParseMessage(msg, rinfo);
Expand Down Expand Up @@ -866,3 +874,17 @@ MiAqaraPlatform.prototype.unregisterPlatformAccessories = function(accessories)
that.AccessoryUtil.remove(accessory.UUID);
});
}

function runOnce(fn, context) { //Control the function to be triggered only once
return function () {
try {
fn.apply(context || this, arguments);
}
catch (e) {
// console.error(e);
}
finally {
fn = null;
}
}
}