Skip to content

Commit f085599

Browse files
committed
Issue #168, N-UPnP discovery endpoint returning invalid bridges for a user which breaks discovery results
1 parent c7e95a6 commit f085599

File tree

7 files changed

+66
-8
lines changed

7 files changed

+66
-8
lines changed

Changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
#5.0.0-alpha.1
4+
- Providing a fix for the discovery portal (N-UPnP search) issues where a user has multiple bridges, where some of
5+
them are invalid. This changes the return value for discovery requiring a major version bump. Issue #168.
6+
37
#4.0.5
48
- Various TypeScript definition fixes including Issue #166.
59

docs/discovery.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async function getBridge() {
3333
getBridge();
3434
```
3535

36-
The results will be an array of discovered bridges with the following structure:
36+
The results will be an array of valid discovered bridges with the following structure:
3737

3838
```json
3939
[
@@ -46,6 +46,22 @@ The results will be an array of discovered bridges with the following structure:
4646
]
4747
```
4848

49+
If a bridge is registered in the Hue portal and returned from the discovery endpoint that is queried but cannot be
50+
connected to for any reason (i.e. it is offline), then the bridge data will be provided in an error object of the form:
51+
52+
```json
53+
{
54+
"error": {
55+
"message": "An error message",
56+
"description": "Failed to connect and load configuration from the bridge at ip address xxx.xxx.xxx.xxx",
57+
"ipaddress": "xxx.xxx.xxx.xxx",
58+
"id": "xxxxxxxxxxxxxxxx"
59+
}
60+
}
61+
```
62+
The `message` value will be that of the underlying error when attempting to resolve the bridge configuration. The `id`
63+
is the mac address reported from the discovery portal and the `ipaddress` is that of the recorded ip address from the
64+
discovery portal.
4965

5066

5167
## UPnP Search

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
//
66

77
const v3 = require('./lib/v3')
8+
, discovery = require('./lib/api/discovery')
89
, ApiError = require('./lib/ApiError')
910
;
1011

1112
module.exports = {
1213
v3: v3,
14+
discovery: discovery,
1315

1416
// This was present in the old API, may need to deprecate it
1517
ApiError: ApiError,

lib/api/discovery/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,18 @@ function loadDescriptions(results) {
3636

3737
function loadConfigurations(results) {
3838
const promises = results.map(result => {
39-
return bridgeValidator.getBridgeConfig(result);
39+
return bridgeValidator
40+
.getBridgeConfig(result)
41+
.catch(err => {
42+
return {
43+
error: {
44+
message: err.message,
45+
description: `Failed to connect and load configuration from the bridge at ip address ${result.ipaddress}`,
46+
ipaddress: result.internalipaddress,
47+
id: result.id,
48+
}
49+
};
50+
});
4051
});
4152

4253
return Promise.all(promises);

lib/api/discovery/index.test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ describe('discovery', () => {
1717
expect(results[0]).to.have.property('name');
1818
expect(results[0]).to.have.property('ipaddress');
1919

20-
expect(results[0]).to.have.property('model');
21-
expect(results[0].model).to.have.property('name');
22-
expect(results[0].model).to.have.property('number');
23-
expect(results[0].model).to.have.property('serial');
20+
expect(results[0]).to.have.property('modelid');
21+
expect(results[0]).to.have.property('swversion');
2422
});
2523
});
2624

lib/v3.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,39 @@ const api = require('./api/index')
44
, discovery = require('./api/discovery/index')
55
, bridgeModel = require('./model')
66
, ApiError = require('./ApiError')
7+
, util = require('./util')
78
;
89

910
// Definition of the v3 API for node-hue-api
1011
module.exports = {
1112
api: api,
12-
discovery: discovery,
13+
14+
discovery: {
15+
upnpSearch: (timeout) => {
16+
util.deprecatedFunction(
17+
'6.x',
18+
`require('node-hue-api').v3.discovery.upnpSearch()`,
19+
`Use require('node-hue-api').discovery.upnpSearch()`);
20+
return discovery.upnpSearch(timeout);
21+
},
22+
23+
nupnpSearch: () => {
24+
util.deprecatedFunction(
25+
'6.x',
26+
`require('node-hue-api').v3.discovery.nupnpSearch()`,
27+
`Use require('node-hue-api').discovery.nupnpSearch()`);
28+
return discovery.nupnpSearch();
29+
},
30+
31+
description: (ipAddress) => {
32+
util.deprecatedFunction(
33+
'6.x',
34+
`require('node-hue-api').v3.discovery.description(ipAddress)`,
35+
`Use require('node-hue-api').discovery.description(ipAddress)`);
36+
return discovery.description(ipAddress);
37+
},
38+
},
39+
1340

1441
//TODO think about removing this and deferring to the model
1542
lightStates: bridgeModel.lightStates,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "node-hue-api",
33
"description": "Philips Hue API Library for Node.js",
44
"version": "4.0.5",
5-
"author": "Peter Murray <peter.murray@osirisoft.com>",
5+
"author": "Peter Murray <681306+peter-murray@users.noreply.github.com>",
66
"contributors": [
77
{
88
"name": "Peter Murray",

0 commit comments

Comments
 (0)