Johannes Zellner пре 9 година
родитељ
комит
cfeca58d20
2 измењених фајлова са 11 додато и 1 уклоњено
  1. 10 1
      backend/routes.js
  2. 1 0
      backend/server.js

+ 10 - 1
backend/routes.js

@@ -5,6 +5,7 @@ module.exports = {
     getConfig: getGeneric('getConfig'),
     getFullState: getGeneric('getFullState'),
     getLights: getGeneric('lights'),
+    getLight: getLight,
     setLight: setLight
 };
 
@@ -24,13 +25,21 @@ function init(hueConfig, callback) {
 function getGeneric(name) {
     return function (req, res) {
         api[name](function (error, result) {
-            if (error) return res.send(500, 'Unable to get t' + name);
+            if (error) return res.send(500, 'Unable to get ' + name);
 
             res.send(200, result);
         });
     };
 }
 
+function getLight(req, res) {
+    api.lightStatus(req.params.id, function (error, result) {
+        if (error) return res.send(500, 'Unable to get state of light ' + req.params.id);
+
+        res.send(200, result);
+    });
+}
+
 function setLight(req, res) {
     console.log('set light: %s', req.params.id, req.body);
 

+ 1 - 0
backend/server.js

@@ -19,6 +19,7 @@ function init(hueConfig) {
     app.get ('/api/config', routes.getConfig);
     app.get ('/api/fullState', routes.getFullState);
     app.get ('/api/lights', routes.getLights);
+    app.get ('/api/lights/:id', routes.getLight);
     app.put ('/api/lights/:id', routes.setLight);
 
     routes.init(hueConfig, function (error) {