EntertainmentApi.test.js
1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
'use strict';
const expect = require('chai').expect
, HueApi = require('../../v3').api
, discovery = require('../../v3').discovery
, testValues = require('../../../test/support/testValues.js') //TODO move these
;
const ENTERTAINMENT_GROUP_ID = 29;
describe.skip('Hue Entertainment API', () => {
let hue;
before(() => {
return discovery.nupnpSearch()
.then(searchResults => {
return HueApi.create(searchResults[0].ipaddress, testValues.username, testValues.clientkey)
.then(api => {
hue = api;
});
});
});
describe('#start()', () => {
it('should start the Entertainment API', async () => {
expect(hue.entertainment).to.not.be.undefined;
const entertainment = await hue.entertainment.start(ENTERTAINMENT_GROUP_ID);
const stopped = await entertainment.stop();
expect(stopped).to.be.true;
});
});
describe('#sendRGB()', function () {
this.timeout(20000);
it('should send an RGB payload', async () => {
const changes = [
{
39: [255, 0, 0],
40: [0, 255, 0]
},
{
39: [0, 255, 0],
40: [255, 0, 0]
}
];
expect(hue.entertainment).to.not.be.undefined;
const entertainment = await hue.entertainment.start(ENTERTAINMENT_GROUP_ID);
const start = Date.now()
, end = start + (10 * 1000)
;
let idx = 0
, time = Date.now()
;
do {
const now = Date.now();
if (now - time > 500) {
console.log('Changing index');
idx++;
time = now;
if (idx >= changes.length) {
idx = 0;
}
const result = entertainment.sendRGB(changes[idx]);
console.log(result);
}
} while (Date.now() <= end);
const stopped = await entertainment.stop();
expect(stopped).to.be.true;
});
});
});