diff --git a/README.md b/README.md index a6984ca..51ecf64 100644 --- a/README.md +++ b/README.md @@ -93,3 +93,6 @@ Change the RGB colour of the light. Note 0,0,0, is not `off`. ### client.rename(light,name,cb) Change the light's name to the string `name`, where `light` is the index received from `client.clients()`. + +### client.brightness(light, birghtnessValue,cb) +Control the brightness of a single light, where `light` is the index received from `client.clients()` and `birghtnessValue` is in range 0 - 255. At value 0 the light will switch off. diff --git a/lib/Hue.js b/lib/Hue.js index 849686a..8d65190 100644 --- a/lib/Hue.js +++ b/lib/Hue.js @@ -269,3 +269,23 @@ Hue.prototype.station = function(config,cb) { return this; }; +/** + * Control brightness of one light. + * @param light {String} id of a light to work with + * @param brightnessValue {Integer} value from 0 to 255 for min to max brightness + * @param cb {Function} callback function + */ +Hue.prototype.brightness = function(light, brightnessValue, cb) { + var opts = { + method:'PUT', + url:'http://'+this._station+'/api/'+this._key+'/lights/'+light+'/state', + json:{on: brightnessValue > 0, bri:brightnessValue % 256}, + timeout:30000 + }; + + request(opts,function(e,r,b) { + if (e) cb(e) + else if (typeof cb === "function") cb.apply(this,Helpers.parseHueResponse(b)); + }); + return this; +}; diff --git a/package.json b/package.json index 9fe5972..42ae96c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hue.js", - "version": "0.2.13", + "version": "0.2.14", "description": "Library for interacting with a Phillips Hue base station", "main": "index.js", "scripts": { @@ -26,5 +26,8 @@ "author": { "name": "Daniel Friedman" }, + "contributors": [ + {"name": "Valentin Alexeev", "email": "valentin.alekseev@gmail.com"} + ], "license": "MIT" }