forked from elliots/ninja-hue2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
49 lines (41 loc) · 1.13 KB
/
test.js
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
'use strict';
var EventEmitter = require('events').EventEmitter;
var opts;
try {
opts = require('./config.json');
} catch(e) {
opts = require('./package.json').config || {};
}
var app = new EventEmitter();
app.log = {
debug: console.log,
info: console.log,
warn: console.log,
error: console.log
};
var driver = new (require('./index'))(opts, app);
driver.log = app.log;
driver.on('register', function(device) {
console.log('Driver.register', device);
device.on('data', function(value) {
console.log('Device.emit data', value);
});
if (device.D == 1008) { //It's a light
setInterval(function() {
device.write({bri:254,sat:254,hue:Math.floor(Math.random()* 65535),on:true,transitionTime:0});
}, 1000);
}/*
if (device.D == 238) { //It's a relay
var x = false;
setInterval(function() {
device.write(x=!x);
}, 1000);
}*/
});
driver.save = function(config) {
console.log('Saving opts', config||opts);
require('fs').writeFileSync('./config.json', JSON.stringify(config||opts));
};
setTimeout(function() {
app.emit('client::up');
}, 500);