| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- 'use strict';
- module.exports = {
- init: init,
- getConfig: getConfig,
- getLights: getLights,
- setLight: setLight
- };
- var hue = require('node-hue-api'),
- HueApi = hue.HueApi,
- lightState = hue.lightState,
- Color = require('color');
- var api = null;
- function init(hueConfig, callback) {
- api = new HueApi(hueConfig.host, hueConfig.username);
- callback();
- }
- function getConfig(req, res) {
- api.config(function (error, result) {
- if (error) return res.send(500, 'Unable to connect to bridge');
- res.send(200, result);
- });
- }
- function getLights(req, res) {
- api.lights(function (error, result) {
- if (error) return res.send(500, error);
- console.log('lights:', result);
- res.send(200, result);
- });
- }
- function setLight(req, res) {
- console.log('set light: %s to color %s', req.params.id, req.body.color);
- var color = new Color(req.body.color);
- var state = lightState.create().rgb(color.rgb().array());
- api.setLightState(req.params.id, state, function (error, result) {
- if (error) return res.send(500, error);
- res.send(200, {});
- });
- }
|