diff --git a/config.schema.json b/config.schema.json index 90d5f3d..8d3abe3 100644 --- a/config.schema.json +++ b/config.schema.json @@ -26,6 +26,11 @@ "description": "Create an additional Lightbulb service for the LED.", "type": "boolean" }, + "excludeAirPlay": { + "title": "Exclude AirPlay 2", + "description": "Exclude AirPlay 2 zoneplayers that are already exposed to Apple's Home app.", + "type": "boolean" + }, "service": { "description": "HomeKit service for ZonePlayer.", "type": "string", @@ -97,7 +102,8 @@ "items": [ "speakers", "alarms", - "leds" + "leds", + "excludeAirPlay" ] }, { diff --git a/lib/ZpPlatform.js b/lib/ZpPlatform.js index 938c64f..7750238 100644 --- a/lib/ZpPlatform.js +++ b/lib/ZpPlatform.js @@ -95,6 +95,7 @@ function ZpPlatform (log, config) { this.name = config.name || 'ZP' this.host = config.host || '0.0.0.0' this.port = config.port || 0 + this.excludeAirPlay = config.excludeAirPlay this.nameScheme = config.nameScheme || '% Sonos' this.packageJson = packageJson this.my = my @@ -134,7 +135,6 @@ function ZpPlatform (log, config) { this.subscriptionTimeout *= 60 // seconds this.zpAccessories = {} - this.zpAccessoryList = [] var msg = util.format( '%s v%s, node %s, homebridge v%s', packageJson.name, @@ -165,9 +165,21 @@ function ZpPlatform (log, config) { // Called by homebridge to retrieve static list of ZpAccessories. ZpPlatform.prototype.accessories = function (callback) { + const accessoryList = [] // Allow for search to find all Sonos ZonePlayers. setTimeout(() => { - return callback(this.zpAccessoryList) + for (const id in this.zpAccessories) { + const zpAccessory = this.zpAccessories[id] + if (zpAccessory.capabilities.airPlay && this.excludeAirPlay) { + this.log( + '%s: %s already exposed through AirPlay 2', + zpAccessory.name, zpAccessory.zp.modelName + ) + } else { + accessoryList.push(zpAccessory) + } + } + return callback(accessoryList) }, this.searchTimeout) const npmRegistry = new homebridgeLib.RestClient({ host: 'registry.npmjs.org', @@ -299,7 +311,6 @@ ZpPlatform.prototype.findPlayers = function () { } const accessory = new ZpAccessory(this, zp) this.zpAccessories[zp.id] = accessory - this.zpAccessoryList.push(accessory) } } })