zetta-honeywell-total-connect-light-driver
Version:
A Zetta driver for lights connected to Honeywell Total Connect
36 lines (32 loc) • 1.19 kB
JavaScript
var util = require('util');
var extend = require('node.extend');
var IMAGE_URL_ROOT = 'http://www.zettaapi.org/icons/';
var IMAGE_EXTENSION = '.png';
var stateImageForDevice = function(device) {
return IMAGE_URL_ROOT + device.type + '-' + device.state + IMAGE_EXTENSION;
}
module.exports = function(server) {
['light'].forEach(function(deviceType){
var deviceQuery = server.where({ type: deviceType});
server.observe([deviceQuery], function(device) {
var states = Object.keys(device._allowed);
for (i = 0; i < states.length; i++) {
device._allowed[states[i]].push('update-state-image');
}
device._transitions['update-state-image'] = {
handler: function(updatedStateImage, cb) {
this.style = extend(this.style, {stateImage: updatedStateImage});
cb();
},
fields: [
{name: 'image', type: 'text'}
]
};
device.call('update-state-image', stateImageForDevice(device));
var stateStream = device.createReadStream('state');
stateStream.on('data', function(newState) {
device.call('update-state-image', stateImageForDevice(device));
});
});
});
}