all files / Insteon/ IO.js

100% Statements 20/20
100% Branches 4/4
100% Functions 5/5
100% Lines 20/20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35                              
var utils = require('./utils');
 
function IO(id, insteon) {
  this.id = id;
  this.insteon = insteon;
}
 
IO.prototype.on = function (port) {
  port = utils.toByte(port | 0);
  return this.insteon.directCommand(this.id, '45', port);
};
 
IO.prototype.off = function (port) {
  port = utils.toByte(port | 0);
  return this.insteon.directCommand(this.id, '46', port);
};
 
IO.prototype.set = function (data) {
  data = utils.toByte(data | 0);
  return this.insteon.directCommand(this.id, '48', data);
};
 
 
IO.prototype.cancelPending = function(port) {
  if(port !== null && port !== undefined) {
    port = utils.toByte(port | 0);
    var portMatch = new RegExp('^....' + this.id + '..4[5-6]' + port + '$');
    this.insteon.cancelPending(portMatch);
  } else {
    this.insteon.cancelPending(this.id);
  }
};
 
module.exports = IO;