node-zway
Version:
Node JS interface for Z-Way (Razberry)
33 lines (25 loc) • 749 B
JavaScript
;
const classDefinitions = require('./commandclasses');
class Device {
constructor(deviceApi, id, commandClasses) {
var self = this;
this._api = deviceApi;
this._id = id;
commandClasses = commandClasses || [];
if (!Array.isArray(commandClasses)) {
commandClasses = [commandClasses];
}
this._commandClasses = commandClasses;
this._commandClasses.forEach(cls => {
var className = classDefinitions.names[cls];
var classDefinition = classDefinitions[cls];
if (classDefinition) {
self[cls] = self[className] = classDefinition(deviceApi, id);
}
});
}
on(eventId, cb) {
this._api.on(this._id, '*', eventId, cb);
}
}
module.exports = exports = Device;