mirror of
https://github.com/mtan93/homebridge.git
synced 2026-03-08 21:02:38 +00:00
Implemented LIFx bulb platform
This commit is contained in:
@@ -14,11 +14,12 @@
|
|||||||
"ad2usb": "git+https://github.com/alistairg/node-ad2usb.git#local",
|
"ad2usb": "git+https://github.com/alistairg/node-ad2usb.git#local",
|
||||||
"carwingsjs": "0.0.x",
|
"carwingsjs": "0.0.x",
|
||||||
"color": "0.10.x",
|
"color": "0.10.x",
|
||||||
"elkington": "kevinohara80/elkington",
|
|
||||||
"eibd": "^0.3.1",
|
"eibd": "^0.3.1",
|
||||||
|
"elkington": "kevinohara80/elkington",
|
||||||
"hap-nodejs": "git+https://github.com/KhaosT/HAP-NodeJS#6bf0f9eaaa2d87db8d1768114c61f4acbb095c41",
|
"hap-nodejs": "git+https://github.com/KhaosT/HAP-NodeJS#6bf0f9eaaa2d87db8d1768114c61f4acbb095c41",
|
||||||
"harmonyhubjs-client": "^1.1.4",
|
"harmonyhubjs-client": "^1.1.4",
|
||||||
"harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git",
|
"harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git",
|
||||||
|
"lifx-api": "^1.0.1",
|
||||||
"mdns": "^2.2.4",
|
"mdns": "^2.2.4",
|
||||||
"node-hue-api": "^1.0.5",
|
"node-hue-api": "^1.0.5",
|
||||||
"node-icontrol": "^0.1.4",
|
"node-icontrol": "^0.1.4",
|
||||||
|
|||||||
174
platforms/LIFx.js
Normal file
174
platforms/LIFx.js
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
var types = require("HAP-NodeJS/accessories/types.js");
|
||||||
|
var lifxObj = require('lifx-api');
|
||||||
|
var lifx;
|
||||||
|
|
||||||
|
function LIFxPlatform(log, config){
|
||||||
|
|
||||||
|
// auth info
|
||||||
|
this.access_token = config["access_token"];
|
||||||
|
|
||||||
|
lifx = new lifxObj(this.access_token);
|
||||||
|
|
||||||
|
this.log = log;
|
||||||
|
}
|
||||||
|
|
||||||
|
LIFxPlatform.prototype = {
|
||||||
|
accessories: function(callback) {
|
||||||
|
this.log("Fetching LIFx devices.");
|
||||||
|
|
||||||
|
var that = this;
|
||||||
|
var foundAccessories = [];
|
||||||
|
|
||||||
|
lifx.listLights("all", function(body) {
|
||||||
|
var bulbs = JSON.parse(body);
|
||||||
|
|
||||||
|
for(var i = 0; i < bulbs.length; i ++) {
|
||||||
|
var bulb = bulbs[i];
|
||||||
|
var accessory = new LIFxBulbAccessory(
|
||||||
|
that.log,
|
||||||
|
bulb.label,
|
||||||
|
bulb.uuid,
|
||||||
|
bulb.model,
|
||||||
|
bulb.id
|
||||||
|
);
|
||||||
|
foundAccessories.push(accessory);
|
||||||
|
}
|
||||||
|
callback(foundAccessories)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function LIFxBulbAccessory(log, label, serial, model, deviceId) {
|
||||||
|
// device info
|
||||||
|
this.name = label;
|
||||||
|
this.model = model;
|
||||||
|
this.deviceId = deviceId;
|
||||||
|
this.serial = serial;
|
||||||
|
this.log = log;
|
||||||
|
}
|
||||||
|
|
||||||
|
LIFxBulbAccessory.prototype = {
|
||||||
|
getPower: function(callback){
|
||||||
|
var that = this;
|
||||||
|
|
||||||
|
lifx.listLights("all", function(body) {
|
||||||
|
var bulbs = JSON.parse(body);
|
||||||
|
|
||||||
|
for(var i = 0; i < bulbs.length; i ++) {
|
||||||
|
var bulb = bulbs[i];
|
||||||
|
|
||||||
|
if(bulb.deviceId == that.deviceId) {
|
||||||
|
return bulb.state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "off";
|
||||||
|
});
|
||||||
|
|
||||||
|
nest.fetchStatus(function (data) {
|
||||||
|
var device = data.shared[that.deviceId];
|
||||||
|
that.log("Target temperature for " + this.name + " is: " + device.target_temperature);
|
||||||
|
callback(device.target_temperature);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
setPower: function(state){
|
||||||
|
var that = this;
|
||||||
|
this.log("Setting power state for heating cooling for " + this.name + " to: " + targetTemperatureType);
|
||||||
|
lifx.setPower("all", state, 1, function (body) {
|
||||||
|
this.log("body");
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
getServices: function() {
|
||||||
|
var that = this;
|
||||||
|
var chars= [{
|
||||||
|
sType: types.ACCESSORY_INFORMATION_STYPE,
|
||||||
|
characteristics: [{
|
||||||
|
cType: types.NAME_CTYPE,
|
||||||
|
onUpdate: null,
|
||||||
|
perms: ["pr"],
|
||||||
|
format: "string",
|
||||||
|
initialValue: this.name,
|
||||||
|
supportEvents: false,
|
||||||
|
supportBonjour: false,
|
||||||
|
manfDescription: "Name of the accessory",
|
||||||
|
designedMaxLength: 255
|
||||||
|
},{
|
||||||
|
cType: types.MANUFACTURER_CTYPE,
|
||||||
|
onUpdate: null,
|
||||||
|
perms: ["pr"],
|
||||||
|
format: "string",
|
||||||
|
initialValue: "LIFx",
|
||||||
|
supportEvents: false,
|
||||||
|
supportBonjour: false,
|
||||||
|
manfDescription: "Manufacturer",
|
||||||
|
designedMaxLength: 255
|
||||||
|
},{
|
||||||
|
cType: types.MODEL_CTYPE,
|
||||||
|
onUpdate: null,
|
||||||
|
perms: ["pr"],
|
||||||
|
format: "string",
|
||||||
|
initialValue: this.model,
|
||||||
|
supportEvents: false,
|
||||||
|
supportBonjour: false,
|
||||||
|
manfDescription: "Model",
|
||||||
|
designedMaxLength: 255
|
||||||
|
},{
|
||||||
|
cType: types.SERIAL_NUMBER_CTYPE,
|
||||||
|
onUpdate: null,
|
||||||
|
perms: ["pr"],
|
||||||
|
format: "string",
|
||||||
|
initialValue: this.serial,
|
||||||
|
supportEvents: false,
|
||||||
|
supportBonjour: false,
|
||||||
|
manfDescription: "SN",
|
||||||
|
designedMaxLength: 255
|
||||||
|
},{
|
||||||
|
cType: types.IDENTIFY_CTYPE,
|
||||||
|
onUpdate: null,
|
||||||
|
perms: ["pw"],
|
||||||
|
format: "bool",
|
||||||
|
initialValue: true,
|
||||||
|
supportEvents: false,
|
||||||
|
supportBonjour: false,
|
||||||
|
manfDescription: "Identify Accessory",
|
||||||
|
designedMaxLength: 1
|
||||||
|
}]
|
||||||
|
}, {
|
||||||
|
sType: types.LIGHTBULB_STYPE,
|
||||||
|
characteristics: [{
|
||||||
|
cType: types.NAME_CTYPE,
|
||||||
|
onUpdate: null,
|
||||||
|
perms: ["pr"],
|
||||||
|
format: "string",
|
||||||
|
initialValue: this.name,
|
||||||
|
supportEvents: false,
|
||||||
|
supportBonjour: false,
|
||||||
|
manfDescription: "Name of LIFx bulb",
|
||||||
|
designedMaxLength: 255
|
||||||
|
}, {
|
||||||
|
cType: types.POWER_STATE_CTYPE,
|
||||||
|
onUpdate: function (value) {
|
||||||
|
that.setPower(value);
|
||||||
|
},
|
||||||
|
onRead: function (callback) {
|
||||||
|
that.getPower(function (state) {
|
||||||
|
callback(state);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
perms: ["pw", "pr", "ev"],
|
||||||
|
format: "int",
|
||||||
|
initialValue: 0,
|
||||||
|
supportEvents: false,
|
||||||
|
supportBonjour: false,
|
||||||
|
manfDescription: "Power state",
|
||||||
|
designedMinValue: 0,
|
||||||
|
designedMaxValue: 1,
|
||||||
|
designedMinStep: 1
|
||||||
|
}]
|
||||||
|
}];
|
||||||
|
return chars;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.accessory = LIFxBulbAccessory;
|
||||||
|
module.exports.platform = LIFxPlatform;
|
||||||
Reference in New Issue
Block a user