mirror of
https://github.com/mtan93/homebridge.git
synced 2026-04-13 14:23:09 +01:00
fix network scan and logging
This commit is contained in:
@@ -98,32 +98,36 @@ var locateBridge = function (callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
that.log(
|
that.log(
|
||||||
"Philips Hue bridges found:",
|
"Philips Hue bridges found:\n" +
|
||||||
bridges.map(function (bridge) {
|
(bridges.map(function (bridge) {
|
||||||
// Bridge name is only returned from meethue.com so use id instead if it isn't there
|
// Bridge name is only returned from meethue.com so use id instead if it isn't there
|
||||||
return '\t' + (bridge.name || bridge.id) + bridge.ipaddress + '\n';
|
return "\t" + bridge.ipaddress + ' - ' + (bridge.name || bridge.id);
|
||||||
})
|
})).join("\n")
|
||||||
);
|
);
|
||||||
|
|
||||||
callback(null, bridges[0].ipaddress);
|
callback(null, bridges[0].ipaddress);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Try to discover the bridge ip using meethue.com
|
// Try to discover the bridge ip using meethue.com
|
||||||
that.log("Attempting to discover Philips Hue bridge with network scan.");
|
that.log("Attempting to discover Philips Hue bridge with meethue.com...");
|
||||||
hue.nupnpSearch(function (locateError, bridges) {
|
hue.nupnpSearch(function (locateError, bridges) {
|
||||||
if (locateError) {
|
if (locateError) {
|
||||||
that.log("Philips Hue bridge discovery with meethue.com failed. Register your bridge with the meethue.com for more reiable discovery.");
|
that.log("Philips Hue bridge discovery with meethue.com failed. Register your bridge with the meethue.com for more reiable discovery.");
|
||||||
|
|
||||||
that.log("Attempting to discover Philips Hue bridge with network scan.");
|
that.log("Attempting to discover Philips Hue bridge with network scan...");
|
||||||
|
|
||||||
|
// Timeout after one minute
|
||||||
|
hue.upnpSearch(60000)
|
||||||
|
.then(function (bridges) {
|
||||||
|
that.log("Scan complete")
|
||||||
|
|
||||||
hue.upnpSearch(function (searchError, bridges) {
|
|
||||||
if (err) {
|
|
||||||
that.log("Philips Hue bridge discovery with network scan failed. Check your network connection or set ip_address manually in configuration.");
|
|
||||||
getIp(new Error("Scan failed"));
|
|
||||||
} else {
|
|
||||||
getIp(null, bridges);
|
getIp(null, bridges);
|
||||||
}
|
})
|
||||||
});
|
.fail(function (scanError) {
|
||||||
|
that.log("Philips Hue bridge discovery with network scan failed. Check your network connection or set ip_address manually in configuration.");
|
||||||
|
|
||||||
|
getIp(new Error("Scan failed: " + scanError.message));
|
||||||
|
}).done();
|
||||||
} else {
|
} else {
|
||||||
getIp(null, bridges);
|
getIp(null, bridges);
|
||||||
}
|
}
|
||||||
@@ -155,6 +159,8 @@ PhilipsHuePlatform.prototype = {
|
|||||||
// Discover the bridge if needed
|
// Discover the bridge if needed
|
||||||
if (!this.ip_address) {
|
if (!this.ip_address) {
|
||||||
locateBridge.call(this, function (err, ip_address) {
|
locateBridge.call(this, function (err, ip_address) {
|
||||||
|
if (err) throw err;
|
||||||
|
|
||||||
// TODO: Find a way to persist this
|
// TODO: Find a way to persist this
|
||||||
that.ip_address = ip_address;
|
that.ip_address = ip_address;
|
||||||
that.log("Save the Philips Hue bridge ip address "+ ip_address +" to your config to skip discovery.");
|
that.log("Save the Philips Hue bridge ip address "+ ip_address +" to your config to skip discovery.");
|
||||||
|
|||||||
Reference in New Issue
Block a user