Last active
January 4, 2016 21:39
-
-
Save RussNelson/8682092 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// define the prototype that will be instantiated when the bulb is discovered | |
// later, we will create a ...perform function, and a ...update function. | |
var LIFX = exports.Device = function(deviceID, deviceUID, info) { | |
console.log("create new bulb"); | |
var self = this; | |
logger.info("create new bulb",deviceID, deviceUID, info); | |
self.whatami = info.deviceType; | |
self.deviceID = deviceID.toString(); | |
self.deviceUID = deviceUID; | |
self.name = info.device.name; | |
self.getName(); | |
self.bulb = info.bulb; | |
broker.subscribe('actors', function(request, taskID, actor, perform, parameter) { | |
if (actor !== ('device/' + self.deviceID)) return; | |
if (request === 'perform') return self.perform(self, taskID, perform, parameter); | |
}); | |
}; | |
exports.start = function() { | |
console.log("start"); | |
var logger2 = utility.logger('discovery'); | |
steward.actors.device.lighting.LIFX = steward.actors.device.lighting.LIFX || | |
{ $info : { type: '/device/lighting/LIFX' } }; | |
steward.actors.device.lighting.LIFX.led = | |
{ $info : { type : '/device/lighting/LIFX/led' | |
, observe : [ ] | |
, perform : [ 'off', 'on' ] | |
, properties : { name : true | |
, status : [ 'waiting', 'on', 'off' ] | |
, color : { model: [ { rgb : { r: 'u8', g: 'u8', b: 'u8' } } | |
, { hue : { hue: 'degrees', saturation: 'percentage' } } | |
] | |
} | |
, brightness : 'percentage' | |
} | |
} | |
, $validate : { perform : validate_perform } | |
}; | |
devices.makers['/device/lighting/LIFX/led'] = LIFX; | |
// LIFX: when the hardware driver discovers a new bulb, it will call us. | |
// LIFX: or if the low-level driver needs to be polled, then create a 'scan' function and call it periodically. | |
lx = lifx.init().on('bulb', function(bulb) { | |
console.log("found new bulb", bulb); | |
var info; | |
info = { source : 'LIFX' | |
, bulb : bulb | |
, device : { url : null | |
, name : bulb.name | |
, manufacturer : "LIFX" | |
, model : { name : bulb.name | |
} | |
, unit : { serial : bulb.lifxAddress | |
, udn : 'LIFX:' + + bulb.lifxAddress.toString('hex') | |
} | |
} | |
, deviceType : '/device/lighting/LIFX/led' | |
}; | |
// if multiple bulb types, update info.deviceType as appropriate | |
info.url = info.device.url; | |
info.deviceType = '/device/lighting/LIFX/led'; | |
info.id = info.device.unit.udn; | |
if (!!devices.devices[info.id]) return; | |
logger2.info("LIFX new bulb:", info.device.name); | |
devices.discover(info); | |
}).on('bulbstate', function(bulbstate) { | |
console.log("bulbstate", bulbstate); | |
var dev, udn; | |
udn = 'LIFX:' + bulbstate.bulb.lifxAddress.toString('hex'); | |
console.log("bulbstate", udn); | |
if (!devices.devices[udn]) return; | |
dev = devices.devices[udn].device; | |
console.log("bulbstate", dev); | |
bulb.logger("bulbstate bulb", dev); | |
dev.update(dev, bulbstate.state); | |
}).on('bulbonoff', function(bulbonoff) { | |
console.log("bulbstate", bulbonoff); | |
var dev, udn; | |
udn = 'LIFX:' + bulbonoff.bulb.lifxAddress.toString('hex'); | |
if (!devices.devices[udn]) return; | |
dev = devices.devices[udn].device; | |
dev.logger(dev); | |
dev.update(dev, { power: bulbonoff.on ? 65535 : 0 }); | |
}).logger = logger2; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
found new bulb { lifxAddress: <Buffer d0 73 d5 00 29 1b>, name: 'Hallway' } | |
info: [discovery] LIFX new bulb: Hallway | |
bulbstate { bulb: { lifxAddress: <Buffer d0 73 d5 00 29 1b>, name: 'Hallway' }, | |
state: | |
{ hue: 0, | |
saturation: 0, | |
brightness: 3763, | |
kelvin: 4500, | |
dim: 0, | |
power: 65535, | |
bulbLabel: 'Hallway', | |
tags: <Buffer 00 00 00 00 00 00 00 00> } } | |
bulbstate LIFX:d073d500291b | |
bulbstate undefined | |
alert: [steward] exception diagnostic=Cannot call method 'update' of undefined | |
alert: [steward] exception stack=[{"fileName":"/home/pi/steward/steward/devices/devices-lighting/lighting-lifx.js","lineNumber":222,"functionName":"Lifx.lifx.init.on.on.on.udn","typeName":"Lifx","methodName":"lifx.init.on.on.on.udn","columnNumber":9,"native":false},{"fileName":"events.js","lineNumber":95,"functionName":"Lifx.EventEmitter.emit","typeName":"Lifx","methodName":"EventEmitter.emit","columnNumber":17,"native":false},{"fileName":"/home/pi/steward/steward/node_modules/lifx/lifx.js","lineNumber":139,"functionName":"Lifx.foundBulb","typeName":"Lifx","methodName":"foundBulb","columnNumber":7,"native":false},{"fileName":"/home/pi/steward/steward/node_modules/lifx/lifx.js","lineNumber":89,"functionName":"Lifx._gotPacket","typeName":"Lifx","methodName":"_gotPacket","columnNumber":9,"native":false},{"fileName":"/home/pi/steward/steward/node_modules/lifx/lifx.js","lineNumber":80,"functionName":"","typeName":"Gateway","methodName":null,"columnNumber":31,"native":false},{"fileName":"events.js","lineNumber":98,"functionName":"Gateway.EventEmitter.emit","typeName":"Gateway","methodName":"EventEmitter.emit","columnNumber":17,"native":false},{"fileName":"/home/pi/steward/steward/node_modules/lifx/lifx.js","lineNumber":180,"functionName":"","typeName":"Socket","methodName":null,"columnNumber":8,"native":false},{"fileName":"events.js","lineNumber":95,"functionName":"Socket.EventEmitter.emit","typeName":"Socket","methodName":"EventEmitter.emit","columnNumber":17,"native":false},{"fileName":"_stream_readable.js","lineNumber":746,"functionName":"","typeName":"Socket","methodName":null,"columnNumber":14,"native":false},{"fileName":"events.js","lineNumber":92,"functionName":"Socket.EventEmitter.emit","typeName":"Socket","methodName":"EventEmitter.emit","columnNumber":17,"native":false}] | |
uncaught exception: TypeError: Cannot call method 'update' of undefined |
No change. Should I put a callback like this: devices.discover(info, cb); and see how it gets called?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
try this for the info assignment