UNPKG

10.5 kBtext/coffeescriptView Raw
1Helper = require('hubot-test-helper')
2chai = require 'chai'
3nock = require 'nock'
4fs = require 'fs'
5
6expect = chai.expect
7
8helper = new Helper('../src/philips-hue.coffee')
9
10describe 'philips-hue', ->
11 beforeEach ->
12 process.env.PHILIPS_HUE_IP = '1.2.3.4'
13 process.env.PHILIPS_HUE_HASH = 'abc0123deadbeaf'
14
15 @room = helper.createRoom()
16
17 do nock.disableNetConnect
18
19 nock('http://1.2.3.4')
20 .get("/api/abc0123deadbeaf/config")
21 .reply 200, fs.readFileSync('test/fixtures/config.json')
22
23 nock('http://1.2.3.4')
24 .get("/api/abc0123deadbeaf/groups")
25 .reply 200, fs.readFileSync('test/fixtures/groups.json')
26
27 nock('http://1.2.3.4')
28 .post("/api/abc0123deadbeaf/groups")
29 .reply 200, fs.readFileSync('test/fixtures/group-create.json')
30
31 nock('http://1.2.3.4')
32 .get("/api/abc0123deadbeaf/lights")
33 .reply 200, fs.readFileSync('test/fixtures/lights.json')
34
35 nock('http://1.2.3.4')
36 .get("/api/abc0123deadbeaf/lights/1")
37 .reply 200, fs.readFileSync('test/fixtures/light.json')
38
39 nock('http://1.2.3.4')
40 .delete("/api/abc0123deadbeaf/groups/1")
41 .reply 200, fs.readFileSync('test/fixtures/group-delete.json')
42
43 nock('http://1.2.3.4')
44 .put("/api/abc0123deadbeaf/lights/1/state")
45 .reply 200, fs.readFileSync('test/fixtures/light-update.json')
46
47 nock('http://1.2.3.4')
48 .put("/api/abc0123deadbeaf/groups/0/action")
49 .reply 200, fs.readFileSync('test/fixtures/group-update.json')
50
51 afterEach ->
52 @room.destroy()
53
54 # hubot hue lights
55 it 'returns lights', () ->
56 selfRoom = @room
57 testPromise = new Promise (resolve, reject) ->
58 selfRoom.user.say('alice', '@hubot hue lights')
59 setTimeout(() ->
60 resolve()
61 , 1000)
62
63 testPromise.then ((result) ->
64 expect(selfRoom.messages).to.eql [
65 ['alice', '@hubot hue lights']
66 ['hubot', 'Connected hue lights:']
67 ['hubot', '- 1: \'Hue Lamp 1\'']
68 ['hubot', '- 2: \'Hue Lamp 2\'']
69 ]
70 )
71
72 # hubot hue light <light number>
73 it 'returns single light', () ->
74 selfRoom = @room
75 testPromise = new Promise (resolve, reject) ->
76 selfRoom.user.say('alice', '@hubot hue light 1')
77 setTimeout(() ->
78 resolve()
79 , 1000)
80
81 testPromise.then ((result) ->
82 expect(selfRoom.messages).to.eql [
83 ['alice', '@hubot hue light 1']
84 ['hubot', 'Light Status:']
85 ['hubot', '- On: true']
86 ['hubot', '- Reachable: true']
87 ['hubot', '- Name: \'LC 1\'']
88 ['hubot', '- Model: LC0015 - Living Colors']
89 ['hubot', '- Unique ID: de:ad:be:ef:00:11']
90 ['hubot', '- Software Version: 1.0.3']
91 ]
92 )
93
94 # hubot hue turn light <light number> <on|off>
95 it 'turns a light off', () ->
96 selfRoom = @room
97 testPromise = new Promise (resolve, reject) ->
98 selfRoom.user.say('alice', '@hubot hue turn light 1 off')
99 setTimeout(() ->
100 resolve()
101 , 1000)
102
103 testPromise.then ((result) ->
104 expect(selfRoom.messages).to.eql [
105 ['alice', '@hubot hue turn light 1 off']
106 ['hubot', 'Setting light 1 to off']
107 ]
108 )
109
110 it 'turns a light on', () ->
111 selfRoom = @room
112 testPromise = new Promise (resolve, reject) ->
113 selfRoom.user.say('alice', '@hubot hue turn light 1 on')
114 setTimeout(() ->
115 resolve()
116 , 1000)
117
118 testPromise.then ((result) ->
119 expect(selfRoom.messages).to.eql [
120 ['alice', '@hubot hue turn light 1 on']
121 ['hubot', 'Setting light 1 to on']
122 ]
123 )
124
125 # hubot hue groups
126 it 'returns groups', () ->
127 selfRoom = @room
128 testPromise = new Promise (resolve, reject) ->
129 selfRoom.user.say('alice', '@hubot hue groups')
130 setTimeout(() ->
131 resolve()
132 , 1000)
133
134 testPromise.then ((result) ->
135 expect(selfRoom.messages).to.eql [
136 ['alice', '@hubot hue groups']
137 ['hubot', 'Light groups:']
138 ['hubot', '- 0: \'Lightset 0\' (All)']
139 ['hubot', '- 1: \'Group 1\' (1, 2)']
140 ['hubot', '- 2: \'Group 2\' (3, 4, 5)']
141 ]
142 )
143
144 # hubot hue config
145 it 'returns the configuration', () ->
146 selfRoom = @room
147 testPromise = new Promise (resolve, reject) ->
148 selfRoom.user.say('alice', '@hubot hue config')
149 setTimeout(() ->
150 resolve()
151 , 1000)
152
153 testPromise.then ((result) ->
154 expect(selfRoom.messages).to.eql [
155 ['alice', '@hubot hue config']
156 ['hubot', 'Base Station: \'Philips hue\'']
157 ['hubot', 'IP: 192.168.1.7 / MAC: 00:17:88:00:00:00 / ZigBee Channel: 15']
158 ['hubot', 'Software: 01012917 / API: 1.3.0 / Update Available: 2']
159 ]
160 )
161
162 # hubot hue (alert|alerts) light <light number>
163 it 'alerts a light', () ->
164 selfRoom = @room
165 testPromise = new Promise (resolve, reject) ->
166 selfRoom.user.say('alice', '@hubot hue alert light 1')
167 setTimeout(() ->
168 resolve()
169 , 1000)
170
171 testPromise.then ((result) ->
172 expect(selfRoom.messages).to.eql [
173 ['alice', '@hubot hue alert light 1']
174 ['hubot', 'Setting light 1 to short alert']
175 ]
176 )
177
178 # hubot hue (colors|colorloop|colorloop) (on|off) light <light number>
179 it 'sets a light to colorloop', () ->
180 selfRoom = @room
181 testPromise = new Promise (resolve, reject) ->
182 selfRoom.user.say('alice', '@hubot hue colorloop on light 1')
183 setTimeout(() ->
184 resolve()
185 , 1000)
186
187 testPromise.then ((result) ->
188 expect(selfRoom.messages).to.eql [
189 ['alice', '@hubot hue colorloop on light 1']
190 ['hubot', 'Setting light 1 colorloop to on']
191 ]
192 )
193
194 # hubot hue hsb light <light number> <hue 0-65535> <saturation 0-254> <brightness 0-254>
195 it 'sets a light by HSB value', () ->
196 selfRoom = @room
197 testPromise = new Promise (resolve, reject) ->
198 selfRoom.user.say('alice', '@hubot hue hsb light 1 3000 200 100')
199 setTimeout(() ->
200 resolve()
201 , 1000)
202
203 testPromise.then ((result) ->
204 expect(selfRoom.messages).to.eql [
205 ['alice', '@hubot hue hsb light 1 3000 200 100']
206 ['hubot', 'Setting light 1 to: Hue=3000, Saturation=200, Brightness=100']
207 ]
208 )
209
210 # hubot hue xy light <light number> <x 0.0-1.0> <y 0.0-1.0>
211 it 'sets a light by XY value', () ->
212 selfRoom = @room
213 testPromise = new Promise (resolve, reject) ->
214 selfRoom.user.say('alice', '@hubot hue xy light 1 0.5 0.6')
215 setTimeout(() ->
216 resolve()
217 , 1000)
218
219 testPromise.then ((result) ->
220 expect(selfRoom.messages).to.eql [
221 ['alice', '@hubot hue xy light 1 0.5 0.6']
222 ['hubot', 'Setting light 1 to: X=0.5, Y=0.6']
223 ]
224 )
225
226 # hubot hue ct light <light number> <color temp 153-500>
227 it 'sets a light by CT value', () ->
228 selfRoom = @room
229 testPromise = new Promise (resolve, reject) ->
230 selfRoom.user.say('alice', '@hubot hue ct light 1 200')
231 setTimeout(() ->
232 resolve()
233 , 1000)
234
235 testPromise.then ((result) ->
236 expect(selfRoom.messages).to.eql [
237 ['alice', '@hubot hue ct light 1 200']
238 ['hubot', 'Setting light 1 to: CT=200']
239 ]
240 )
241
242 # hubot hue group <group name>=[<comma separated list of light indexes>]
243 it 'creates a group of lights', () ->
244 selfRoom = @room
245 testPromise = new Promise (resolve, reject) ->
246 selfRoom.user.say('alice', '@hubot hue group livingroom=[1,2,3]')
247 setTimeout(() ->
248 resolve()
249 , 1000)
250
251 testPromise.then ((result) ->
252 expect(selfRoom.messages).to.eql [
253 ['alice', '@hubot hue group livingroom=[1,2,3]']
254 ['hubot', 'Setting livingroom to 1, 2, 3']
255 ['hubot', 'Group created!']
256 ]
257 )
258
259 # hubot hue rm group <group number>
260 it 'removes a group', () ->
261 selfRoom = @room
262 testPromise = new Promise (resolve, reject) ->
263 selfRoom.user.say('alice', '@hubot hue rm group 1')
264 setTimeout(() ->
265 resolve()
266 , 1000)
267
268 testPromise.then ((result) ->
269 expect(selfRoom.messages).to.eql [
270 ['alice', '@hubot hue rm group 1']
271 ['hubot', 'Deleting 1']
272 ['hubot', 'Group deleted!']
273 ]
274 )
275
276 # hubot hue @<group name> <on|off> - turn all lights in <group name> on or off
277 it 'turns a group off', () ->
278 selfRoom = @room
279 testPromise = new Promise (resolve, reject) ->
280 selfRoom.user.say('alice', '@hubot hue @all off')
281 setTimeout(() ->
282 resolve()
283 , 1000)
284
285 testPromise.then ((result) ->
286 expect(selfRoom.messages).to.eql [
287 ['alice', '@hubot hue @all off']
288 ['hubot', 'Setting light group 0 to off']
289 ]
290 )
291
292 it 'turns a group on', () ->
293 selfRoom = @room
294 testPromise = new Promise (resolve, reject) ->
295 selfRoom.user.say('alice', '@hubot hue @all on')
296 setTimeout(() ->
297 resolve()
298 , 1000)
299
300 testPromise.then ((result) ->
301 expect(selfRoom.messages).to.eql [
302 ['alice', '@hubot hue @all on']
303 ['hubot', 'Setting light group 0 to on']
304 ]
305 )
306
307 # hubot hue @<group name> hsb=(<hue>,<sat>,<bri>)
308 it 'sets group by HSB value', () ->
309 selfRoom = @room
310 testPromise = new Promise (resolve, reject) ->
311 selfRoom.user.say('alice', '@hubot hue @all hsb=(3000,200,100)')
312 setTimeout(() ->
313 resolve()
314 , 1000)
315
316 testPromise.then ((result) ->
317 expect(selfRoom.messages).to.eql [
318 ['alice', '@hubot hue @all hsb=(3000,200,100)']
319 ['hubot', 'Setting light group 0 to: Hue=3000, Saturation=200, Brightness=100']
320 ]
321 )
322
323 # hubot hue @<group name> xy=(<x>,<y>)
324 it 'sets group by XY value', () ->
325 selfRoom = @room
326 testPromise = new Promise (resolve, reject) ->
327 selfRoom.user.say('alice', '@hubot hue @all xy=(0.5,0.6)')
328 setTimeout(() ->
329 resolve()
330 , 1000)
331
332 testPromise.then ((result) ->
333 expect(selfRoom.messages).to.eql [
334 ['alice', '@hubot hue @all xy=(0.5,0.6)']
335 ['hubot', 'Setting light group 0 to: X=0.5, Y=0.6']
336 ]
337 )
338
339 # hubot hue @<group name> ct=<color temp>
340 it 'sets group by CT value', () ->
341 selfRoom = @room
342 testPromise = new Promise (resolve, reject) ->
343 selfRoom.user.say('alice', '@hubot hue @all ct=200')
344 setTimeout(() ->
345 resolve()
346 , 1000)
347
348 testPromise.then ((result) ->
349 expect(selfRoom.messages).to.eql [
350 ['alice', '@hubot hue @all ct=200']
351 ['hubot', 'Setting light group 0 to: CT=200']
352 ]
353 )