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:
Raoul
2015-09-08 09:25:44 +02:00
parent b05ee83e9f
commit 1df411d916

View File

@@ -6,6 +6,8 @@ function SonosPlatform(log, config){
this.config = config;
this.name = config["name"];
this.playVolume = config["play_volume"];
// timeout for device discovery
this.discoveryTimeout = (config.deviceDiscoveryTimeout || 10)*1000; // assume 10sec as a default
}
SonosPlatform.prototype = {
@@ -16,6 +18,18 @@ SonosPlatform.prototype = {
// track found devices so we don't add duplicates
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) {
that.log("Found device at " + device.host);
@@ -26,9 +40,13 @@ SonosPlatform.prototype = {
if (!roomNamesFound[roomName]) {
roomNamesFound[roomName] = true;
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
var accessory = new SonosAccessory(that.log, that.config, device, description);
callback([accessory]);
// add it to the collector array
devicesFound.push(accessory);
}
else {
that.log("Ignoring playable device with duplicate room name - " + roomName);