homebridge-dummy 0.3.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -48,3 +48,35 @@ You may also want to create a dummy switch that turns itself on one second after
48
48
  ]
49
49
 
50
50
  ```
51
+
52
+ ## Timed Switches
53
+
54
+ You may also want to create a timed switch that turns itself off after being on for a given time (for example, five seconds). This can be done by passing the 'time' argument in your config.json:
55
+
56
+ ```
57
+ "accessories": [
58
+ {
59
+ "accessory": "DummySwitch",
60
+ "name": "My Stateful Switch 1",
61
+ "time": 5000
62
+ }
63
+ ]
64
+
65
+ ```
66
+
67
+ ## Resettable Timed Switches
68
+
69
+ You may also want to create a timed switch that is reset each time it is activated. This way, the original timer is reset instead of creating a new timer.
70
+ This can be done by passing the 'resettable' argument in your config.json:
71
+
72
+ ```
73
+ "accessories": [
74
+ {
75
+ "accessory": "DummySwitch",
76
+ "name": "My Stateful Switch 1",
77
+ "time": 5000,
78
+ "resettable": true
79
+ }
80
+ ]
81
+
82
+ ```
@@ -0,0 +1,39 @@
1
+ {
2
+ "pluginAlias": "DummySwitch",
3
+ "pluginType": "accessory",
4
+ "singular": false,
5
+ "schema": {
6
+ "type": "object",
7
+ "properties": {
8
+ "name": {
9
+ "title": "Name",
10
+ "type": "string",
11
+ "required": true
12
+ },
13
+ "stateful": {
14
+ "title": "Stateful",
15
+ "type": "boolean",
16
+ "default": false,
17
+ "description": "The switch remains on instead of being automatically turned off."
18
+ },
19
+ "reverse": {
20
+ "title": "Reverse",
21
+ "type": "boolean",
22
+ "default": false,
23
+ "description": "The switch's default state is on."
24
+ },
25
+ "time": {
26
+ "title": "Time",
27
+ "type": "number",
28
+ "default": 1000,
29
+ "description": "The switch will turn off after this number of milliseconds. Not used if the switch is stateful."
30
+ },
31
+ "resettable": {
32
+ "title": "Resettable",
33
+ "type": "boolean",
34
+ "default": false,
35
+ "description": "The timer will reset each time the switch is turned on. "
36
+ }
37
+ }
38
+ }
39
+ }
package/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  var Service, Characteristic, HomebridgeAPI;
4
+ const { HomebridgeDummyVersion } = require('./package.json');
4
5
 
5
6
  module.exports = function(homebridge) {
6
7
 
@@ -10,13 +11,24 @@ module.exports = function(homebridge) {
10
11
  homebridge.registerAccessory("homebridge-dummy", "DummySwitch", DummySwitch);
11
12
  }
12
13
 
14
+
13
15
  function DummySwitch(log, config) {
14
16
  this.log = log;
15
17
  this.name = config.name;
16
18
  this.stateful = config.stateful;
17
19
  this.reverse = config.reverse;
20
+ this.time = config.time ? config.time : 1000;
21
+ this.resettable = config.resettable;
22
+ this.timer = null;
18
23
  this._service = new Service.Switch(this.name);
19
24
 
25
+ this.informationService = new Service.AccessoryInformation();
26
+ this.informationService
27
+ .setCharacteristic(Characteristic.Manufacturer, 'Homebridge')
28
+ .setCharacteristic(Characteristic.Model, 'Dummy Switch')
29
+ .setCharacteristic(Characteristic.FirmwareRevision, HomebridgeDummyVersion)
30
+ .setCharacteristic(Characteristic.SerialNumber, 'Dummy-' + this.name.replace(/\s/g, '-'));
31
+
20
32
  this.cacheDirectory = HomebridgeAPI.user.persistPath();
21
33
  this.storage = require('node-persist');
22
34
  this.storage.initSync({dir:this.cacheDirectory, forgiveParseErrors: true});
@@ -37,7 +49,7 @@ function DummySwitch(log, config) {
37
49
  }
38
50
 
39
51
  DummySwitch.prototype.getServices = function() {
40
- return [this._service];
52
+ return [this.informationService, this._service];
41
53
  }
42
54
 
43
55
  DummySwitch.prototype._setOn = function(on, callback) {
@@ -45,13 +57,19 @@ DummySwitch.prototype._setOn = function(on, callback) {
45
57
  this.log("Setting switch to " + on);
46
58
 
47
59
  if (on && !this.reverse && !this.stateful) {
48
- setTimeout(function() {
60
+ if (this.resettable) {
61
+ clearTimeout(this.timer);
62
+ }
63
+ this.timer = setTimeout(function() {
49
64
  this._service.setCharacteristic(Characteristic.On, false);
50
- }.bind(this), 1000);
65
+ }.bind(this), this.time);
51
66
  } else if (!on && this.reverse && !this.stateful) {
52
- setTimeout(function() {
67
+ if (this.resettable) {
68
+ clearTimeout(this.timer);
69
+ }
70
+ this.timer = setTimeout(function() {
53
71
  this._service.setCharacteristic(Characteristic.On, true);
54
- }.bind(this), 1000);
72
+ }.bind(this), this.time);
55
73
  }
56
74
 
57
75
  if (this.stateful) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homebridge-dummy",
3
- "version": "0.3.0",
3
+ "version": "0.6.0",
4
4
  "description": "Dummy switches for Homebridge: https://github.com/nfarina/homebridge",
5
5
  "license": "ISC",
6
6
  "keywords": [
@@ -1,556 +0,0 @@
1
- [
2
- {
3
- "id": "33300ac17-on-0",
4
- "name": "Feet up on 0",
5
- "lights": [
6
- "1",
7
- "2",
8
- "3"
9
- ],
10
- "active": true
11
- },
12
- {
13
- "id": "0f2c67d80-on-0",
14
- "name": "Blue rain on 0",
15
- "lights": [
16
- "1",
17
- "2",
18
- "3"
19
- ],
20
- "active": true
21
- },
22
- {
23
- "id": "fd499c3e2-on-0",
24
- "name": "Taj on 0",
25
- "lights": [
26
- "1",
27
- "2",
28
- "3"
29
- ],
30
- "active": true
31
- },
32
- {
33
- "id": "3896c310d-on-0",
34
- "name": "Jump! on 0",
35
- "lights": [
36
- "1",
37
- "2",
38
- "3"
39
- ],
40
- "active": true
41
- },
42
- {
43
- "id": "797106fb9-on-0",
44
- "name": "Hammock on 0",
45
- "lights": [
46
- "1",
47
- "2",
48
- "3"
49
- ],
50
- "active": true
51
- },
52
- {
53
- "id": "64b4aa87e-on-0",
54
- "name": "Laila on 0",
55
- "lights": [
56
- "1",
57
- "2",
58
- "3"
59
- ],
60
- "active": true
61
- },
62
- {
63
- "id": "e07a35d7e-on-0",
64
- "name": "Greece on 0",
65
- "lights": [
66
- "1",
67
- "2",
68
- "3"
69
- ],
70
- "active": true
71
- },
72
- {
73
- "id": "e915785b2-on-0",
74
- "name": "Reading on 0",
75
- "lights": [
76
- "1",
77
- "2",
78
- "3"
79
- ],
80
- "active": true
81
- },
82
- {
83
- "id": "84fa88aa5-on-0",
84
- "name": "Energize on 0",
85
- "lights": [
86
- "1",
87
- "2",
88
- "3"
89
- ],
90
- "active": true
91
- },
92
- {
93
- "id": "ac637e2f0-on-0",
94
- "name": "Relax on 0",
95
- "lights": [
96
- "1",
97
- "2",
98
- "3"
99
- ],
100
- "active": true
101
- },
102
- {
103
- "id": "f5d73dbdd-on-0",
104
- "name": "Concentrate on 0",
105
- "lights": [
106
- "1",
107
- "2",
108
- "3"
109
- ],
110
- "active": true
111
- },
112
- {
113
- "id": "b0cae7c0f-on-0",
114
- "name": "Family Room on 0",
115
- "lights": [
116
- "1",
117
- "2",
118
- "3",
119
- "4",
120
- "5",
121
- "6",
122
- "7",
123
- "9",
124
- "10",
125
- "11",
126
- "12",
127
- "13",
128
- "14",
129
- "15"
130
- ],
131
- "active": true
132
- },
133
- {
134
- "id": "54ae5d997-on-0",
135
- "name": "Ski on 0",
136
- "lights": [
137
- "1",
138
- "2",
139
- "3"
140
- ],
141
- "active": true
142
- },
143
- {
144
- "id": "6b6ca6a0d-on-0",
145
- "name": "Beach on 0",
146
- "lights": [
147
- "1",
148
- "2",
149
- "3"
150
- ],
151
- "active": true
152
- },
153
- {
154
- "id": "087f88f52-on-0",
155
- "name": "Sunset on 0",
156
- "lights": [
157
- "1",
158
- "2",
159
- "3"
160
- ],
161
- "active": true
162
- },
163
- {
164
- "id": "2e1dbbb4a-on-0",
165
- "name": "Pencils on 0",
166
- "lights": [
167
- "1",
168
- "2",
169
- "3"
170
- ],
171
- "active": true
172
- },
173
- {
174
- "id": "2141cb8bd-on-0",
175
- "name": "Deep sea on 0",
176
- "lights": [
177
- "1",
178
- "2",
179
- "3"
180
- ],
181
- "active": true
182
- },
183
- {
184
- "id": "f2b600f90-on-0",
185
- "name": "Kathy on 0",
186
- "lights": [
187
- "1",
188
- "2",
189
- "3"
190
- ],
191
- "active": true
192
- },
193
- {
194
- "id": "358853161-on-0",
195
- "name": "SATCO on 0",
196
- "lights": [
197
- "1",
198
- "2",
199
- "3"
200
- ],
201
- "active": true
202
- },
203
- {
204
- "id": "0df0d8410-on-0",
205
- "name": "TV on 0",
206
- "lights": [
207
- "1",
208
- "2",
209
- "3",
210
- "4",
211
- "5",
212
- "6"
213
- ],
214
- "active": true
215
- },
216
- {
217
- "id": "b1ff92641-on-0",
218
- "name": "TV on 0",
219
- "lights": [
220
- "1",
221
- "2",
222
- "3",
223
- "4",
224
- "5",
225
- "6",
226
- "7",
227
- "9",
228
- "10",
229
- "11",
230
- "12",
231
- "13",
232
- "14",
233
- "15"
234
- ],
235
- "active": true
236
- },
237
- {
238
- "id": "7e21bd918-on-0",
239
- "name": "TV on 0",
240
- "lights": [
241
- "1",
242
- "2",
243
- "3",
244
- "4",
245
- "5",
246
- "6",
247
- "7",
248
- "9",
249
- "10",
250
- "11",
251
- "12",
252
- "13",
253
- "14",
254
- "15"
255
- ],
256
- "active": true
257
- },
258
- {
259
- "id": "672422585-on-0",
260
- "name": "Hangout on 0",
261
- "lights": [
262
- "1",
263
- "2",
264
- "3"
265
- ],
266
- "active": true
267
- },
268
- {
269
- "id": "2ef4ff39f-on-0",
270
- "name": "Relaxing on 0",
271
- "lights": [
272
- "1",
273
- "2",
274
- "3"
275
- ],
276
- "active": true
277
- },
278
- {
279
- "id": "dd3046b79-on-0",
280
- "name": "Bedroom on 0",
281
- "lights": [
282
- "1",
283
- "2",
284
- "3"
285
- ],
286
- "active": true
287
- },
288
- {
289
- "id": "02b12e930-off-0",
290
- "name": "3 lights off",
291
- "lights": [
292
- "1",
293
- "2",
294
- "3"
295
- ],
296
- "active": true
297
- },
298
- {
299
- "id": "beaaf9826-on-0",
300
- "name": "Relaxing on 0",
301
- "lights": [
302
- "1",
303
- "2",
304
- "3"
305
- ],
306
- "active": true
307
- },
308
- {
309
- "id": "f1c0e1d4b-on-0",
310
- "name": "Hangout on 0",
311
- "lights": [
312
- "1",
313
- "2",
314
- "3"
315
- ],
316
- "active": true
317
- },
318
- {
319
- "id": "OFF-TAP-1",
320
- "name": "Tap scene 1",
321
- "lights": [
322
- "1",
323
- "2",
324
- "3"
325
- ],
326
- "active": true
327
- },
328
- {
329
- "id": "TAP-2",
330
- "name": "Tap scene 2",
331
- "lights": [
332
- "1",
333
- "2",
334
- "3"
335
- ],
336
- "active": true
337
- },
338
- {
339
- "id": "TAP-3",
340
- "name": "Tap scene 3",
341
- "lights": [
342
- "1",
343
- "2",
344
- "3"
345
- ],
346
- "active": true
347
- },
348
- {
349
- "id": "TAP-4",
350
- "name": "Tap scene 4",
351
- "lights": [
352
- "1",
353
- "2",
354
- "3"
355
- ],
356
- "active": true
357
- },
358
- {
359
- "id": "5707a1666-on-0",
360
- "name": "TV on 0",
361
- "lights": [
362
- "1",
363
- "2",
364
- "3"
365
- ],
366
- "active": true
367
- },
368
- {
369
- "id": "f84ddb8fe-on-0",
370
- "name": "Daylight on 0",
371
- "lights": [
372
- "1",
373
- "2",
374
- "3"
375
- ],
376
- "active": true
377
- },
378
- {
379
- "id": "4eaf358d8-on-0",
380
- "name": "Relax on 0",
381
- "lights": [
382
- "1",
383
- "2",
384
- "3",
385
- "4",
386
- "5",
387
- "6"
388
- ],
389
- "active": true
390
- },
391
- {
392
- "id": "1df07f572-off-0",
393
- "name": "6 lights off",
394
- "lights": [
395
- "1",
396
- "2",
397
- "3",
398
- "4",
399
- "5",
400
- "6"
401
- ],
402
- "active": true
403
- },
404
- {
405
- "id": "442c3441f-on-0",
406
- "name": "Dimmed on 0",
407
- "lights": [
408
- "1",
409
- "2",
410
- "3",
411
- "4",
412
- "5",
413
- "6"
414
- ],
415
- "active": true
416
- },
417
- {
418
- "id": "ON-DIMMER",
419
- "name": "Dimmer scene",
420
- "lights": [
421
- "1",
422
- "2",
423
- "3",
424
- "4",
425
- "5",
426
- "6",
427
- "7",
428
- "8",
429
- "9"
430
- ],
431
- "active": true
432
- },
433
- {
434
- "id": "fc08438b0-on-0",
435
- "name": "Relax on 0",
436
- "lights": [
437
- "1",
438
- "2",
439
- "3",
440
- "4",
441
- "5",
442
- "6",
443
- "9",
444
- "10",
445
- "11",
446
- "12",
447
- "13"
448
- ],
449
- "active": true
450
- },
451
- {
452
- "id": "0f58637a8-on-0",
453
- "name": "Relax on 0",
454
- "lights": [
455
- "1",
456
- "2",
457
- "3",
458
- "4",
459
- "5",
460
- "6",
461
- "7",
462
- "9",
463
- "10",
464
- "11",
465
- "12",
466
- "13",
467
- "14",
468
- "15"
469
- ],
470
- "active": true
471
- },
472
- {
473
- "id": "0205ab766-off-0",
474
- "name": "14 lights off",
475
- "lights": [
476
- "1",
477
- "2",
478
- "3",
479
- "4",
480
- "5",
481
- "6",
482
- "7",
483
- "9",
484
- "10",
485
- "11",
486
- "12",
487
- "13",
488
- "14",
489
- "15"
490
- ],
491
- "active": true
492
- },
493
- {
494
- "id": "7e1165625-on-0",
495
- "name": "Family Room on 0",
496
- "lights": [
497
- "1",
498
- "2",
499
- "3",
500
- "4",
501
- "5",
502
- "6",
503
- "7",
504
- "9",
505
- "10",
506
- "11",
507
- "12",
508
- "13",
509
- "14",
510
- "15"
511
- ],
512
- "active": true
513
- },
514
- {
515
- "id": "faa918d0f-on-0",
516
- "name": "Living Room on 0",
517
- "lights": [
518
- "1",
519
- "2",
520
- "3",
521
- "4",
522
- "5",
523
- "6",
524
- "7",
525
- "9",
526
- "10",
527
- "11",
528
- "12",
529
- "13",
530
- "14",
531
- "15"
532
- ],
533
- "active": true
534
- },
535
- {
536
- "id": "426146c8d-on-0",
537
- "name": "Family Room on 0",
538
- "lights": [
539
- "1",
540
- "2",
541
- "3",
542
- "4",
543
- "5",
544
- "6",
545
- "7",
546
- "9",
547
- "10",
548
- "11",
549
- "12",
550
- "13",
551
- "14",
552
- "15"
553
- ],
554
- "active": true
555
- }
556
- ]