Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

Commit

Permalink
1.3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Zefau authored Jul 1, 2020
1 parent 2b1a678 commit 181c3fd
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 183 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ Connect your Philips Hue Lights with ioBroker.

## Changelog

Please also see [release page](https://github.com/Zefau/ioBroker.hue-extended/releases) for changelog and detailed information.
### 1.3.7 (2020-07-01)
- (Zefau) added additional verification checks of the response received from the Hue Bridge (see [#45](https://github.com/Zefau/ioBroker.hue-extended/issues/45))
- (Zefau) fixed long-time polling for connection retry after connection fails serval times on short-time polling (see [#58](https://github.com/Zefau/ioBroker.hue-extended/issues/58))

### 1.3.6 (2020-05-31)
- (Zefau) added long-time polling for connection retry after connection fails serval times on short-time polling (see [#58](https://github.com/Zefau/ioBroker.hue-extended/issues/58))
Expand Down
24 changes: 19 additions & 5 deletions hue-extended.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const _SUBSCRIPTIONS = require(__dirname + '/_NODES.js').SUBSCRIPTIONS;

const _MAPPING_BRIDGE = Object.keys(_MAPPING);
const _MAPPING_STATES = Object.values(_MAPPING);
const _CHANNELS = ['config', 'groups', 'lights', 'resourcelinks', 'rules', 'scenes', 'schedules', 'sensors'];

/*
* variables initiation
Expand Down Expand Up @@ -567,13 +568,12 @@ function getPayload(refresh)
_request({ ...REQUEST_OPTIONS, 'uri': bridge, resolveWithFullResponse: true }).then(response => {
let payload = response.body;

// error handler
if (response.statusCode !== 200) {
adapter.log.error('Error while retrieving payload from Hue Bridge (Status Code ' + response.statusCode + ')!');
return false;
throw new Error('Error while retrieving payload from Hue Bridge (Status Code ' + response.statusCode + ')');
}
else if (!payload || (payload[0] && payload[0].error)) {
adapter.log.error('Error while retrieving payload from Hue Bridge' + (payload[0] && payload[0].error ? ': ' + payload[0].error.description : '!'));
return false;
throw new Error('Error while retrieving payload from Hue Bridge' + (payload[0] && payload[0].error ? ': ' + payload[0].error.description : ''));
}

// add meta data
Expand Down Expand Up @@ -628,6 +628,11 @@ function getPayload(refresh)
// go through channels
for (let channel in payload) {

// verify channel
if (_CHANNELS.indexOf(channel) === -1) {
throw new Error('Incorrect data return from Hue API');
}

// create channel
library.set({
'node': channel,
Expand All @@ -637,9 +642,18 @@ function getPayload(refresh)

// sync all groups
if (channel == 'groups') {
_request({ ...REQUEST_OPTIONS, 'uri': bridge + channel + '/0' }).then(pl => {
_request({ ...REQUEST_OPTIONS, 'uri': bridge + channel + '/0', resolveWithFullResponse: true }).then(res => {
let pl = res.body;
pl.name = 'All Lights';

// error handler
if (res.statusCode !== 200) {
throw new Error('Error while retrieving payload from Hue Bridge (Status Code ' + res.statusCode + ')');
}
else if (!pl || (pl[0] && pl[0].error)) {
throw new Error('Error while retrieving payload from Hue Bridge' + (pl[0] && pl[0].error ? ': ' + pl[0].error.description : ''));
}

// index
DEVICES[channel] = JSON.parse(JSON.stringify(payload[channel]));
DEVICES[channel][0] = JSON.parse(JSON.stringify(pl));
Expand Down
Loading

0 comments on commit 181c3fd

Please sign in to comment.