Skip to content

Commit

Permalink
Add option not to discover deCONZ gateways
Browse files Browse the repository at this point in the history
  • Loading branch information
ebaauw committed Sep 23, 2023
1 parent 8d07e93 commit 22613e5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
8 changes: 5 additions & 3 deletions cli/ph.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ ${description.discover}
Parameters:
${b('-h')} Print this help and exit.
${b('-n')} Do not discover deCONZ gateways.
${b('-S')} Stealth mode, only use local discovery.`,
config: `${description.ph}
Expand Down Expand Up @@ -827,13 +828,14 @@ class Main extends CommandLineTool {

async discover (...args) {
const parser = new CommandLineParser(packageJson)
let stealth = false
const params = {}
parser
.help('h', 'help', help.discover)
.flag('S', 'stealth', () => { stealth = true })
.flag('n', 'noDeconz', () => { params.noDeconz = true })
.flag('S', 'stealth', () => { params.stealth = true })
.parse(...args)
const jsonFormatter = new JsonFormatter({ sortKeys: true })
const bridges = await this.hueDiscovery.discover(stealth)
const bridges = await this.hueDiscovery.discover(params)
this.print(jsonFormatter.stringify(bridges))
}

Expand Down
5 changes: 5 additions & 0 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@
"type": "boolean",
"default": true
},
"noDeconz": {
"description": "Do not discover deCONZ gateways",
"type": "boolean"
},
"noResponse": {
"description": "Report unreachable lights as <i>No Response</i> in HomeKit.",
"type": "boolean"
Expand Down Expand Up @@ -223,6 +227,7 @@
"title": "Migration",
"description": "Migrate to Homebridge deCONZ and/or Homebridge Hue2.",
"items": [
"noDeconz",
"homebridgeDeconz",
"homebridgeHue2"
]
Expand Down
26 changes: 16 additions & 10 deletions lib/HueDiscovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,29 +120,35 @@ class HueDiscovery extends events.EventEmitter {
* does a local search over mDSN (Bonjour) and UPnP.
* Calls {@link HueDiscovery#config config()} for each discovered bridge or
* gateway for verification.
* @param {boolean} [stealth=false] - Don't query discovery portals.
* @param {object} params - Parameters.
* @param {boolean} [params.stealth=false] - Don't query discovery portals.
* @param {boolean} [params.noDeconz=false] - Don't discover deCONZ gateways.
* @return {object} response - Response object with a key/value pair per
* found bridge / gateway. The key is the host (IP address or hostname and
* port), the value is the return value of
* {@link HueDiscovery#config config()}.
*/
async discover (stealth = false) {
async discover (params = {}) {
this.bridgeMap = {}
this.jobs = []
this.jobs.push(this._bonjour())
this.jobs.push(this._upnp())
if (!stealth) {
if (!params.noDeconz) {
this.jobs.push(this._upnp())
}
if (!params.stealth) {
this.jobs.push(this._nupnp({
name: 'meethue.com',
https: !this._options.forceHttp,
host: 'discovery.meethue.com'
}))
this.jobs.push(this._nupnp({
name: 'phoscon.de',
https: !this._options.forceHttp,
host: 'phoscon.de',
path: '/discover'
}))
if (!params.noDeconz) {
this.jobs.push(this._nupnp({
name: 'phoscon.de',
https: !this._options.forceHttp,
host: 'phoscon.de',
path: '/discover'
}))
}
}
for (const job of this.jobs) {
await job
Expand Down
8 changes: 6 additions & 2 deletions lib/HuePlatform.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ function HuePlatform (log, configJson, homebridge) {
.intKey('lowBattery', 0, 100)
.boolKey('nativeHomeKitLights')
.boolKey('nativeHomeKitSensors')
.boolKey('noDeconz')
.boolKey('noResponse')
.boolKey('ownResourcelinks')
.intKey('parallelRequests', 1, 30)
Expand Down Expand Up @@ -445,10 +446,13 @@ HuePlatform.prototype.findBridges = async function () {
}
try {
this.log.info(
'searching bridges and gateways%s',
'searching bridges%s%s', this.config.noDeconz ? '' : ' and gateways',
this.config.stealth ? ' (stealth mode)' : ''
)
const map = await this.hueDiscovery.discover(this.config.stealth)
const map = await this.hueDiscovery.discover({
noDeconz: this.config.noDeconz,
stealth: this.config.stealth
})
if (Object.keys(map).length > 0) {
return map
}
Expand Down

0 comments on commit 22613e5

Please sign in to comment.