diff --git a/Changelog.md b/Changelog.md index 55b6546..1aba351 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,9 @@ # Change Log +#5.0.0-alpha.1 +- Providing a fix for the discovery portal (N-UPnP search) issues where a user has multiple bridges, where some of +them are invalid. This changes the return value for discovery requiring a major version bump. Issue #168. + #4.0.5 - Various TypeScript definition fixes including Issue #166. diff --git a/docs/discovery.md b/docs/discovery.md index 7a1123d..d9e8e46 100644 --- a/docs/discovery.md +++ b/docs/discovery.md @@ -33,7 +33,7 @@ async function getBridge() { getBridge(); ``` -The results will be an array of discovered bridges with the following structure: +The results will be an array of valid discovered bridges with the following structure: ```json [ @@ -46,6 +46,22 @@ The results will be an array of discovered bridges with the following structure: ] ``` +If a bridge is registered in the Hue portal and returned from the discovery endpoint that is queried but cannot be +connected to for any reason (i.e. it is offline), then the bridge data will be provided in an error object of the form: + +```json +{ + "error": { + "message": "An error message", + "description": "Failed to connect and load configuration from the bridge at ip address xxx.xxx.xxx.xxx", + "ipaddress": "xxx.xxx.xxx.xxx", + "id": "xxxxxxxxxxxxxxxx" + } +} +``` + The `message` value will be that of the underlying error when attempting to resolve the bridge configuration. The `id` + is the mac address reported from the discovery portal and the `ipaddress` is that of the recorded ip address from the + discovery portal. ## UPnP Search diff --git a/index.js b/index.js index c94f20b..b9c0e05 100644 --- a/index.js +++ b/index.js @@ -5,11 +5,13 @@ // const v3 = require('./lib/v3') + , discovery = require('./lib/api/discovery') , ApiError = require('./lib/ApiError') ; module.exports = { v3: v3, + discovery: discovery, // This was present in the old API, may need to deprecate it ApiError: ApiError, diff --git a/lib/api/discovery/index.js b/lib/api/discovery/index.js index 152615b..6ff2525 100644 --- a/lib/api/discovery/index.js +++ b/lib/api/discovery/index.js @@ -36,7 +36,18 @@ function loadDescriptions(results) { function loadConfigurations(results) { const promises = results.map(result => { - return bridgeValidator.getBridgeConfig(result); + return bridgeValidator + .getBridgeConfig(result) + .catch(err => { + return { + error: { + message: err.message, + description: `Failed to connect and load configuration from the bridge at ip address ${result.ipaddress}`, + ipaddress: result.internalipaddress, + id: result.id, + } + }; + }); }); return Promise.all(promises); diff --git a/lib/api/discovery/index.test.js b/lib/api/discovery/index.test.js index 91ca5f8..16a6473 100644 --- a/lib/api/discovery/index.test.js +++ b/lib/api/discovery/index.test.js @@ -17,10 +17,8 @@ describe('discovery', () => { expect(results[0]).to.have.property('name'); expect(results[0]).to.have.property('ipaddress'); - expect(results[0]).to.have.property('model'); - expect(results[0].model).to.have.property('name'); - expect(results[0].model).to.have.property('number'); - expect(results[0].model).to.have.property('serial'); + expect(results[0]).to.have.property('modelid'); + expect(results[0]).to.have.property('swversion'); }); }); diff --git a/lib/v3.js b/lib/v3.js index 75956e9..adb048e 100644 --- a/lib/v3.js +++ b/lib/v3.js @@ -4,12 +4,39 @@ const api = require('./api/index') , discovery = require('./api/discovery/index') , bridgeModel = require('./model') , ApiError = require('./ApiError') + , util = require('./util') ; // Definition of the v3 API for node-hue-api module.exports = { api: api, - discovery: discovery, + + discovery: { + upnpSearch: (timeout) => { + util.deprecatedFunction( + '6.x', + `require('node-hue-api').v3.discovery.upnpSearch()`, + `Use require('node-hue-api').discovery.upnpSearch()`); + return discovery.upnpSearch(timeout); + }, + + nupnpSearch: () => { + util.deprecatedFunction( + '6.x', + `require('node-hue-api').v3.discovery.nupnpSearch()`, + `Use require('node-hue-api').discovery.nupnpSearch()`); + return discovery.nupnpSearch(); + }, + + description: (ipAddress) => { + util.deprecatedFunction( + '6.x', + `require('node-hue-api').v3.discovery.description(ipAddress)`, + `Use require('node-hue-api').discovery.description(ipAddress)`); + return discovery.description(ipAddress); + }, + }, + //TODO think about removing this and deferring to the model lightStates: bridgeModel.lightStates, diff --git a/package.json b/package.json index 5351f3d..2097236 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "node-hue-api", "description": "Philips Hue API Library for Node.js", "version": "4.0.5", - "author": "Peter Murray ", + "author": "Peter Murray <681306+peter-murray@users.noreply.github.com>", "contributors": [ { "name": "Peter Murray",