HueBridge = function(server, username) {
  this.server = server;
  this.username = username;
}

HueBridge.prototype = {

  _apiCall: function(method, path, data, callback) {
    HTTP.call(method, "http://" + this.server + "/api/" + this.username + path, {}, function(error, result) {
      if (error) {
        console.log(error);
      } else if (result.data && result.data[0] && result.data[0].error) {
        let error = result.data[0].error;
        // throw new Meteor.Error(error, );
        console.log(error);
      } else {
        callback(result.data);
      }
    });
  },

  getLights: function(callback) {
    var bridge = this;
    this._apiCall("GET", "/lights/", {}, function(results) {
      let lights = [];
      for (id in results) {
        lights.push(new HueLight(bridge, id, results[id]))
      }
      callback(lights);
    });
  },

  getLight: function(id, callback) {
    var bridge = this;
    this._apiCall("GET", `/lights/${id}`, {}, function(result) {
      let light = new HueLight(bridge, id, result);
      callback(light);
    });
  }
}

HueLight = function(bridge, id, params) {
  this.bridge = bridge;
  this.id = id;
  this.params = params;
}

@@ -248,18 +248,36 @@
  path, %7B
-%7D,
+ data: data %7D,%0A     
  functio
@@ -301,16 +301,18 @@
 %7B%0A      
+ 
+ 
 if (erro
@@ -308,32 +308,34 @@
    if (error) %7B%0A
+  
         console.
@@ -348,24 +348,26 @@
 ror);%0A      
+ 
+ 
 %7D else if (r
@@ -426,24 +426,26 @@
 ) %7B%0A        
+  
 let error = 
@@ -474,18 +474,17 @@
         
-//
+ 
  throw n
@@ -508,41 +508,37 @@
 rror
-, );%0A        console.log(error
+.type, error.description
 );%0A
+  
     
@@ -546,18 +546,56 @@
  %7D else 
-%7B%0A
+if (typeof callback === %22function%22) %7B%0A  
         
@@ -627,15 +627,24 @@
     
+  
 %7D%0A    
-%7D
+  %7D%0A    
 );%0A 
@@ -1241,12 +1241,588 @@
 = params;%0A%7D%0A
+%0AHueLight.prototype = %7B%0A%0A  updateState: function(key, val) %7B%0A    let state = %7B%7D;%0A    state%5Bkey%5D = val;%0A    this.bridge._apiCall(%22PUT%22, %60/lights/$%7Bthis.id%7D/state%60, state);%0A  %7D,%0A%0A  setOn: function() %7B%0A    this.updateState(%22on%22, true);%0A  %7D,%0A%0A  setOff: function() %7B%0A    this.updateState(%22on%22, false);%0A  %7D,%0A%0A  setBrightness: function(value) %7B%0A    if (value %3C 0 %7C%7C value %3E 255 %7C%7C value !== parseInt(value, 10)) %7B%0A      throw new Meteor.Error(500, value + %22 is not a valid brightness value. Should be an integer between 0 and 255.%22);%0A    %7D%0A    this.updateState(%22bri%22, value);%0A  %7D,%0A%7D%0A

Add setOn, setOff and setBrightness methods