Skip to content

Commit b263a55

Browse files
committed
Merge branch 'develop'
2 parents 4760094 + bdc08bc commit b263a55

File tree

14 files changed

+392
-31
lines changed

14 files changed

+392
-31
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,12 @@ null,
201201
vendorName: 'LIFX',
202202
productId: 1,
203203
productName: 'Original 1000',
204-
version: 6
204+
version: 6,
205+
productFeatures: {
206+
color: true,
207+
infrared: false,
208+
multizone: false
209+
}
205210
}
206211
```
207212

example/interactive-cli.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ client.on('light-new', function(light) {
1313
}
1414
console.log('Label: ' + info.label);
1515
console.log('Power:', (info.power === 1) ? 'on' : 'off');
16-
console.log('Color:', info.color, '\n');
16+
console.log('Color:', info.color);
17+
});
18+
19+
light.getHardwareVersion(function(err, info) {
20+
if (err) {
21+
console.log(err);
22+
}
23+
console.log('Device Info: ' + info.vendorName + ' - ' + info.productName);
24+
console.log('Features: ', info.productFeatures, '\n');
1725
});
1826
});
1927

lib/lifx/constants.js

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,9 @@ module.exports = {
4141
RGB_MAXIMUM_VALUE: 255,
4242
RGB_MINIMUM_VALUE: 0,
4343

44-
// Vendor ID values
45-
LIFX_VENDOR_IDS: [
46-
{id: 1, name: 'LIFX'}
47-
],
48-
49-
// Product ID values
50-
LIFX_PRODUCT_IDS: [
51-
{id: 1, name: 'Original 1000'},
52-
{id: 3, name: 'Color 650'},
53-
{id: 10, name: 'White 800 (Low Voltage)'},
54-
{id: 11, name: 'White 800 (High Voltage)'},
55-
{id: 18, name: 'White 900 BR30 (Low Voltage)'},
56-
{id: 19, name: 'White 900 BR30 (High Voltage)'},
57-
{id: 20, name: 'Color 1000 BR30'},
58-
{id: 22, name: 'Color 1000'},
59-
{id: 27, name: 'LIFX A19'},
60-
{id: 28, name: 'LIFX BR30'},
61-
{id: 29, name: 'LIFX+ A19'},
62-
{id: 30, name: 'LIFX+ BR30'},
63-
{id: 31, name: 'LIFX Z'}
64-
],
44+
// Infrared values
45+
IR_MINIMUM_BRIGHTNESS: 0,
46+
IR_MAXIMUM_BRIGHTNESS: 100,
6547

6648
// Waveform values, order is important here
6749
LIGHT_WAVEFORMS: [

lib/lifx/light.js

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,30 @@ Light.prototype.colorRgbHex = function(hexString, duration, callback) {
180180
this.color(hsbObj.h, hsbObj.s, hsbObj.b, 3500, duration, callback);
181181
};
182182

183+
/**
184+
* Sets the Maximum Infrared brightness
185+
* @param {Number} brightness infrared brightness from 0 - 100 (in %)
186+
* @param {Function} [callback] called when light did receive message
187+
*/
188+
Light.prototype.maxIR = function(brightness, callback) {
189+
if (typeof brightness !== 'number' || brightness < constants.IR_MINIMUM_BRIGHTNESS || brightness > constants.IR_MAXIMUM_BRIGHTNESS) {
190+
throw new RangeError('LIFX light setMaxIR method expects brightness to be a number between ' +
191+
constants.IR_MINIMUM_BRIGHTNESS + ' and ' + constants.IR_MAXIMUM_BRIGHTNESS
192+
);
193+
}
194+
brightness = Math.round(brightness / constants.IR_MAXIMUM_BRIGHTNESS * 65535);
195+
196+
if (callback !== undefined && typeof callback !== 'function') {
197+
throw new TypeError('LIFX light setMaxIR method expects callback to be a function');
198+
}
199+
200+
var packetObj = packet.create('setInfrared', {
201+
brightness: brightness
202+
}, this.client.source);
203+
packetObj.target = this.id;
204+
this.client.send(packetObj, callback);
205+
};
206+
183207
/**
184208
* Requests the current state of the light
185209
* @param {Function} callback a function to accept the data
@@ -211,6 +235,28 @@ Light.prototype.getState = function(callback) {
211235
}, sqnNumber);
212236
};
213237

238+
/**
239+
* Requests the current maximum setting for the infrared channel
240+
* @param {Function} callback a function to accept the data
241+
*/
242+
Light.prototype.getMaxIR = function(callback) {
243+
if (typeof callback !== 'function') {
244+
throw new TypeError('LIFX light getMaxIR method expects callback to be a function');
245+
}
246+
var packetObj = packet.create('getInfrared', {}, this.client.source);
247+
packetObj.target = this.id;
248+
var sqnNumber = this.client.send(packetObj);
249+
this.client.addMessageHandler('stateInfrared', function(err, msg) {
250+
if (err) {
251+
return callback(err, null);
252+
}
253+
254+
msg.brightness = Math.round(msg.brightness * (constants.HSBK_MAXIMUM_BRIGHTNESS / 65535));
255+
256+
callback(null, msg.brightness);
257+
}, sqnNumber);
258+
};
259+
214260
/**
215261
* Requests hardware info from the light
216262
* @param {Function} callback a function to accept the data with error and
@@ -227,13 +273,15 @@ Light.prototype.getHardwareVersion = function(callback) {
227273
if (err) {
228274
return callback(err, null);
229275
}
230-
callback(null, _.pick(msg, [
276+
var versionInfo = _.pick(msg, [
231277
'vendorId',
232-
'vendorName',
233278
'productId',
234-
'productName',
235279
'version'
236-
]));
280+
]);
281+
callback(null, _.assign(
282+
versionInfo,
283+
utils.getHardwareDetails(versionInfo.vendorId, versionInfo.productId)
284+
));
237285
}, sqnNumber);
238286
};
239287

lib/lifx/packet.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ Packet.typeList = [
6969
{id: 117, name: 'setPower'},
7070
{id: 118, name: 'statePower'},
7171
// {id: 119, name: 'setWaveformOptional'},
72+
{id: 120, name: 'getInfrared'},
73+
{id: 121, name: 'stateInfrared'},
74+
{id: 122, name: 'setInfrared'},
7275
{id: 401, name: 'getAmbientLight'},
7376
{id: 402, name: 'stateAmbientLight'}
7477
// {id: 403, name: 'getDimmerVoltage'},

lib/lifx/packets/getInfrared.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
var Packet = {
4+
size: 0
5+
};
6+
7+
module.exports = Packet;

lib/lifx/packets/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ packets.setWaveform = require('./setWaveform');
5555
packets.getTemperature = require('./getTemperature');
5656
packets.stateTemperature = require('./stateTemperature');
5757

58+
packets.getInfrared = require('./getInfrared');
59+
packets.setInfrared = require('./setInfrared');
60+
packets.stateInfrared = require('./stateInfrared');
61+
5862
/*
5963
* Sensor related packages
6064
*/

lib/lifx/packets/setInfrared.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
'use strict';
2+
3+
var Packet = {
4+
size: 2
5+
};
6+
7+
/**
8+
* Converts packet specific data from a buffer to an object
9+
* @param {Buffer} buf Buffer containing only packet specific data no header
10+
* @return {Object} Information contained in packet
11+
*/
12+
Packet.toObject = function(buf) {
13+
var obj = {};
14+
var offset = 0;
15+
16+
if (buf.length !== this.size) {
17+
throw new Error('Invalid length given for setInfrared LIFX packet');
18+
}
19+
20+
obj.brightness = buf.readUInt16LE(offset);
21+
offset += 2;
22+
23+
return obj;
24+
};
25+
26+
/**
27+
* Converts the given packet specific object into a packet
28+
* @param {Object} obj object with configuration data
29+
* @param {Number} obj.brightness between 0 and 65535
30+
* @return {Buffer} packet
31+
*/
32+
Packet.toBuffer = function(obj) {
33+
var buf = new Buffer(this.size);
34+
buf.fill(0);
35+
var offset = 0;
36+
37+
if (typeof obj.brightness !== 'number' && obj.brightness < 0 && obj.brightness > 65535) {
38+
throw new RangeError('Invalid brightness given for setInfrared LIFX packet, must be a number between 0 and 65535');
39+
}
40+
buf.writeUInt16LE(obj.brightness, offset);
41+
offset += 2;
42+
43+
return buf;
44+
};
45+
46+
module.exports = Packet;

lib/lifx/packets/stateInfrared.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict';
2+
3+
var Packet = {
4+
size: 2
5+
};
6+
7+
/**
8+
* Converts packet specific data from a buffer to an object
9+
* @param {Buffer} buf Buffer containing only packet specific data no header
10+
* @return {Object} Information contained in packet
11+
*/
12+
Packet.toObject = function(buf) {
13+
var obj = {};
14+
var offset = 0;
15+
16+
if (buf.length !== this.size) {
17+
throw new Error('Invalid length given for stateInfrared LIFX packet');
18+
}
19+
20+
obj.brightness = buf.readUInt16LE(offset);
21+
offset += 2;
22+
23+
return obj;
24+
};
25+
26+
/**
27+
* Converts the given packet specific object into a packet
28+
* @param {Object} obj object with configuration data
29+
* @return {Buffer} packet
30+
*/
31+
Packet.toBuffer = function(obj) {
32+
var buf = new Buffer(this.size);
33+
buf.fill(0);
34+
var offset = 0;
35+
36+
buf.writeUInt16LE(obj.brightness, offset);
37+
offset += 2;
38+
39+
return buf;
40+
};
41+
42+
module.exports = Packet;

lib/lifx/packets/stateVersion.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ Packet.toObject = function(buf) {
2929
offset += 4;
3030

3131
obj.productId = buf.readUInt32LE(offset);
32-
var product = _.find(constants.LIFX_PRODUCT_IDS, {id: obj.productId});
33-
if (product !== undefined) {
34-
obj.productName = product.name;
35-
}
3632
offset += 4;
3733

3834
obj.version = buf.readUInt32LE(offset);

0 commit comments

Comments
 (0)