Skip to content

Commit

Permalink
Issue #168, N-UPnP discovery endpoint returning invalid bridges for a…
Browse files Browse the repository at this point in the history
… user which breaks discovery results
  • Loading branch information
peter-murray committed Mar 9, 2020
1 parent c7e95a6 commit f085599
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 8 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
18 changes: 17 additions & 1 deletion docs/discovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
[
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 12 additions & 1 deletion lib/api/discovery/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions lib/api/discovery/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});

Expand Down
29 changes: 28 additions & 1 deletion lib/v3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "node-hue-api",
"description": "Philips Hue API Library for Node.js",
"version": "4.0.5",
"author": "Peter Murray <peter.murray@osirisoft.com>",
"author": "Peter Murray <681306+peter-murray@users.noreply.github.com>",
"contributors": [
{
"name": "Peter Murray",
Expand Down

0 comments on commit f085599

Please sign in to comment.