Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusRumpf committed Jan 6, 2017
2 parents 4760094 + bdc08bc commit b263a55
Show file tree
Hide file tree
Showing 14 changed files with 392 additions and 31 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,12 @@ null,
vendorName: 'LIFX',
productId: 1,
productName: 'Original 1000',
version: 6
version: 6,
productFeatures: {
color: true,
infrared: false,
multizone: false
}
}
```

Expand Down
10 changes: 9 additions & 1 deletion example/interactive-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ client.on('light-new', function(light) {
}
console.log('Label: ' + info.label);
console.log('Power:', (info.power === 1) ? 'on' : 'off');
console.log('Color:', info.color, '\n');
console.log('Color:', info.color);
});

light.getHardwareVersion(function(err, info) {
if (err) {
console.log(err);
}
console.log('Device Info: ' + info.vendorName + ' - ' + info.productName);
console.log('Features: ', info.productFeatures, '\n');
});
});

Expand Down
24 changes: 3 additions & 21 deletions lib/lifx/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,9 @@ module.exports = {
RGB_MAXIMUM_VALUE: 255,
RGB_MINIMUM_VALUE: 0,

// Vendor ID values
LIFX_VENDOR_IDS: [
{id: 1, name: 'LIFX'}
],

// Product ID values
LIFX_PRODUCT_IDS: [
{id: 1, name: 'Original 1000'},
{id: 3, name: 'Color 650'},
{id: 10, name: 'White 800 (Low Voltage)'},
{id: 11, name: 'White 800 (High Voltage)'},
{id: 18, name: 'White 900 BR30 (Low Voltage)'},
{id: 19, name: 'White 900 BR30 (High Voltage)'},
{id: 20, name: 'Color 1000 BR30'},
{id: 22, name: 'Color 1000'},
{id: 27, name: 'LIFX A19'},
{id: 28, name: 'LIFX BR30'},
{id: 29, name: 'LIFX+ A19'},
{id: 30, name: 'LIFX+ BR30'},
{id: 31, name: 'LIFX Z'}
],
// Infrared values
IR_MINIMUM_BRIGHTNESS: 0,
IR_MAXIMUM_BRIGHTNESS: 100,

// Waveform values, order is important here
LIGHT_WAVEFORMS: [
Expand Down
56 changes: 52 additions & 4 deletions lib/lifx/light.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,30 @@ Light.prototype.colorRgbHex = function(hexString, duration, callback) {
this.color(hsbObj.h, hsbObj.s, hsbObj.b, 3500, duration, callback);
};

/**
* Sets the Maximum Infrared brightness
* @param {Number} brightness infrared brightness from 0 - 100 (in %)
* @param {Function} [callback] called when light did receive message
*/
Light.prototype.maxIR = function(brightness, callback) {
if (typeof brightness !== 'number' || brightness < constants.IR_MINIMUM_BRIGHTNESS || brightness > constants.IR_MAXIMUM_BRIGHTNESS) {
throw new RangeError('LIFX light setMaxIR method expects brightness to be a number between ' +
constants.IR_MINIMUM_BRIGHTNESS + ' and ' + constants.IR_MAXIMUM_BRIGHTNESS
);
}
brightness = Math.round(brightness / constants.IR_MAXIMUM_BRIGHTNESS * 65535);

if (callback !== undefined && typeof callback !== 'function') {
throw new TypeError('LIFX light setMaxIR method expects callback to be a function');
}

var packetObj = packet.create('setInfrared', {
brightness: brightness
}, this.client.source);
packetObj.target = this.id;
this.client.send(packetObj, callback);
};

/**
* Requests the current state of the light
* @param {Function} callback a function to accept the data
Expand Down Expand Up @@ -211,6 +235,28 @@ Light.prototype.getState = function(callback) {
}, sqnNumber);
};

/**
* Requests the current maximum setting for the infrared channel
* @param {Function} callback a function to accept the data
*/
Light.prototype.getMaxIR = function(callback) {
if (typeof callback !== 'function') {
throw new TypeError('LIFX light getMaxIR method expects callback to be a function');
}
var packetObj = packet.create('getInfrared', {}, this.client.source);
packetObj.target = this.id;
var sqnNumber = this.client.send(packetObj);
this.client.addMessageHandler('stateInfrared', function(err, msg) {
if (err) {
return callback(err, null);
}

msg.brightness = Math.round(msg.brightness * (constants.HSBK_MAXIMUM_BRIGHTNESS / 65535));

callback(null, msg.brightness);
}, sqnNumber);
};

/**
* Requests hardware info from the light
* @param {Function} callback a function to accept the data with error and
Expand All @@ -227,13 +273,15 @@ Light.prototype.getHardwareVersion = function(callback) {
if (err) {
return callback(err, null);
}
callback(null, _.pick(msg, [
var versionInfo = _.pick(msg, [
'vendorId',
'vendorName',
'productId',
'productName',
'version'
]));
]);
callback(null, _.assign(
versionInfo,
utils.getHardwareDetails(versionInfo.vendorId, versionInfo.productId)
));
}, sqnNumber);
};

Expand Down
3 changes: 3 additions & 0 deletions lib/lifx/packet.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ Packet.typeList = [
{id: 117, name: 'setPower'},
{id: 118, name: 'statePower'},
// {id: 119, name: 'setWaveformOptional'},
{id: 120, name: 'getInfrared'},
{id: 121, name: 'stateInfrared'},
{id: 122, name: 'setInfrared'},
{id: 401, name: 'getAmbientLight'},
{id: 402, name: 'stateAmbientLight'}
// {id: 403, name: 'getDimmerVoltage'},
Expand Down
7 changes: 7 additions & 0 deletions lib/lifx/packets/getInfrared.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

var Packet = {
size: 0
};

module.exports = Packet;
4 changes: 4 additions & 0 deletions lib/lifx/packets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ packets.setWaveform = require('./setWaveform');
packets.getTemperature = require('./getTemperature');
packets.stateTemperature = require('./stateTemperature');

packets.getInfrared = require('./getInfrared');
packets.setInfrared = require('./setInfrared');
packets.stateInfrared = require('./stateInfrared');

/*
* Sensor related packages
*/
Expand Down
46 changes: 46 additions & 0 deletions lib/lifx/packets/setInfrared.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict';

var Packet = {
size: 2
};

/**
* Converts packet specific data from a buffer to an object
* @param {Buffer} buf Buffer containing only packet specific data no header
* @return {Object} Information contained in packet
*/
Packet.toObject = function(buf) {
var obj = {};
var offset = 0;

if (buf.length !== this.size) {
throw new Error('Invalid length given for setInfrared LIFX packet');
}

obj.brightness = buf.readUInt16LE(offset);
offset += 2;

return obj;
};

/**
* Converts the given packet specific object into a packet
* @param {Object} obj object with configuration data
* @param {Number} obj.brightness between 0 and 65535
* @return {Buffer} packet
*/
Packet.toBuffer = function(obj) {
var buf = new Buffer(this.size);
buf.fill(0);
var offset = 0;

if (typeof obj.brightness !== 'number' && obj.brightness < 0 && obj.brightness > 65535) {
throw new RangeError('Invalid brightness given for setInfrared LIFX packet, must be a number between 0 and 65535');
}
buf.writeUInt16LE(obj.brightness, offset);
offset += 2;

return buf;
};

module.exports = Packet;
42 changes: 42 additions & 0 deletions lib/lifx/packets/stateInfrared.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict';

var Packet = {
size: 2
};

/**
* Converts packet specific data from a buffer to an object
* @param {Buffer} buf Buffer containing only packet specific data no header
* @return {Object} Information contained in packet
*/
Packet.toObject = function(buf) {
var obj = {};
var offset = 0;

if (buf.length !== this.size) {
throw new Error('Invalid length given for stateInfrared LIFX packet');
}

obj.brightness = buf.readUInt16LE(offset);
offset += 2;

return obj;
};

/**
* Converts the given packet specific object into a packet
* @param {Object} obj object with configuration data
* @return {Buffer} packet
*/
Packet.toBuffer = function(obj) {
var buf = new Buffer(this.size);
buf.fill(0);
var offset = 0;

buf.writeUInt16LE(obj.brightness, offset);
offset += 2;

return buf;
};

module.exports = Packet;
4 changes: 0 additions & 4 deletions lib/lifx/packets/stateVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ Packet.toObject = function(buf) {
offset += 4;

obj.productId = buf.readUInt32LE(offset);
var product = _.find(constants.LIFX_PRODUCT_IDS, {id: obj.productId});
if (product !== undefined) {
obj.productName = product.name;
}
offset += 4;

obj.version = buf.readUInt32LE(offset);
Expand Down
116 changes: 116 additions & 0 deletions lib/lifx/products.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
[
{
"vid": 1,
"name": "LIFX",
"products": [
{
"pid": 1,
"name": "Original 1000",
"features": {
"color": true,
"infrared": false,
"multizone": false
}
},
{
"pid": 3,
"name": "Color 650",
"features": {
"color": true,
"infrared": false,
"multizone": false
}
},
{
"pid": 10,
"name": "White 800 (Low Voltage)",
"features": {
"color": false,
"infrared": false,
"multizone": false
}
},
{
"pid": 11,
"name": "White 800 (High Voltage)",
"features": {
"color": false,
"infrared": false,
"multizone": false
}
},
{
"pid": 18,
"name": "White 900 BR30 (Low Voltage)",
"features": {
"color": false,
"infrared": false,
"multizone": false
}
},
{
"pid": 20,
"name": "Color 1000 BR30",
"features": {
"color": true,
"infrared": false,
"multizone": false
}
},
{
"pid": 22,
"name": "Color 1000",
"features": {
"color": true,
"infrared": false,
"multizone": false
}
},
{
"pid": 27,
"name": "LIFX A19",
"features": {
"color": true,
"infrared": false,
"multizone": false
}
},
{
"pid": 28,
"name": "LIFX BR30",
"features": {
"color": true,
"infrared": false,
"multizone": false
}
},
{
"pid": 29,
"name": "LIFX+ A19",
"features": {
"color": true,
"infrared": true,
"multizone": false
}
},
{
"pid": 30,
"name": "LIFX+ BR30",
"features": {
"color": true,
"infrared": true,
"multizone": false
}
},
{
"pid": 31,
"name": "LIFX Z",
"features": {
"color": true,
"infrared": false,
"multizone": true
}
}
]
}
]
Loading

0 comments on commit b263a55

Please sign in to comment.