Skip to content

Commit

Permalink
Optionally exclude AirPlay 2 zoneplayers.
Browse files Browse the repository at this point in the history
Zoneplayers that support AirPlay 2 already appear in Apple's Home app.  When `"excludeAirPlay": true` is set in config.json, these zoneplayers aren't exposed by homebridge-zp.  See #74.
  • Loading branch information
ebaauw committed May 31, 2019
1 parent 3882162 commit 5e874b5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
8 changes: 7 additions & 1 deletion config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -97,7 +102,8 @@
"items": [
"speakers",
"alarms",
"leds"
"leds",
"excludeAirPlay"
]
},
{
Expand Down
17 changes: 14 additions & 3 deletions lib/ZpPlatform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -299,7 +311,6 @@ ZpPlatform.prototype.findPlayers = function () {
}
const accessory = new ZpAccessory(this, zp)
this.zpAccessories[zp.id] = accessory
this.zpAccessoryList.push(accessory)
}
}
})
Expand Down

0 comments on commit 5e874b5

Please sign in to comment.