-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
43 lines (34 loc) · 929 Bytes
/
server.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
var HomebridgeAdapter = require('./lib/homebridge').Adapter;
var LifxAdapter = require('./lib/lifx').Adapter;
var express = require('express');
var app = express();
var hueAdapter = new HomebridgeAdapter({
platform: 'homebridge-philipshue.PhilipsHue'
});
var lifxAdapter = new LifxAdapter();
app.get('/update', function(req, res) {
var platform = req.query.platform;
var power = (req.query.power === 'true');
var hue = req.query.hue;
var saturation = req.query.saturation;
var adapter;
if (platform === 'philips-hue') {
adapter = hueAdapter;
} else if (platform === 'lifx') {
adapter = lifxAdapter;
}
if (power) {
adapter.turnOn();
} else {
adapter.turnOff();
}
if (hue) {
adapter.changeHue(hue);
}
if (saturation) {
adapter.changeSaturation(saturation);
}
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify({}));
});
app.listen(3000);