mirror of
https://github.com/mtan93/homebridge.git
synced 2026-04-10 06:13:11 +01:00
TESTING NEEDED
Proposing idea to de-asynchronize Sonos device discovery with a timeout event for push. I have no IDE at hand right now, so please check syntax before merging! I have no Sonos devices, so please check somebody with the hardware at hand! Thanks Raoul
This commit is contained in:
@@ -6,6 +6,8 @@ function SonosPlatform(log, config){
|
|||||||
this.config = config;
|
this.config = config;
|
||||||
this.name = config["name"];
|
this.name = config["name"];
|
||||||
this.playVolume = config["play_volume"];
|
this.playVolume = config["play_volume"];
|
||||||
|
// timeout for device discovery
|
||||||
|
this.discoveryTimeout = (config.deviceDiscoveryTimeout || 10)*1000; // assume 10sec as a default
|
||||||
}
|
}
|
||||||
|
|
||||||
SonosPlatform.prototype = {
|
SonosPlatform.prototype = {
|
||||||
@@ -16,6 +18,18 @@ SonosPlatform.prototype = {
|
|||||||
// track found devices so we don't add duplicates
|
// track found devices so we don't add duplicates
|
||||||
var roomNamesFound = {};
|
var roomNamesFound = {};
|
||||||
|
|
||||||
|
// collector array for the devices from callbacks
|
||||||
|
var devicesFound = [];
|
||||||
|
// tell the sonos callbacks if timeout already occured
|
||||||
|
var timeout = false;
|
||||||
|
|
||||||
|
// the timeout event will push the accessories back
|
||||||
|
setTimeout(function(){
|
||||||
|
timeout=true;
|
||||||
|
callback(devicesFound);
|
||||||
|
}, this.discoveryTimeout);
|
||||||
|
|
||||||
|
|
||||||
sonos.search(function (device) {
|
sonos.search(function (device) {
|
||||||
that.log("Found device at " + device.host);
|
that.log("Found device at " + device.host);
|
||||||
|
|
||||||
@@ -26,9 +40,13 @@ SonosPlatform.prototype = {
|
|||||||
if (!roomNamesFound[roomName]) {
|
if (!roomNamesFound[roomName]) {
|
||||||
roomNamesFound[roomName] = true;
|
roomNamesFound[roomName] = true;
|
||||||
that.log("Found playable device - " + roomName);
|
that.log("Found playable device - " + roomName);
|
||||||
|
if (timeout) {
|
||||||
|
that.log("Ignored: Discovered after timeout (Set deviceDiscoveryTimeout parameter in Sonos section of config.json)");
|
||||||
|
}
|
||||||
// device is an instance of sonos.Sonos
|
// device is an instance of sonos.Sonos
|
||||||
var accessory = new SonosAccessory(that.log, that.config, device, description);
|
var accessory = new SonosAccessory(that.log, that.config, device, description);
|
||||||
callback([accessory]);
|
// add it to the collector array
|
||||||
|
devicesFound.push(accessory);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
that.log("Ignoring playable device with duplicate room name - " + roomName);
|
that.log("Ignoring playable device with duplicate room name - " + roomName);
|
||||||
|
|||||||
Reference in New Issue
Block a user