Merge pull request #154 from snowdd1/patch-1

TESTING NEEDED: Sonos platform multiple devices (for #95, #153)
This commit is contained in:
Nick Farina
2015-09-08 06:27:29 -07:00

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);