all files / Insteon/ Door.js

100% Statements 29/29
100% Branches 12/12
100% Functions 2/2
100% Lines 29/29
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49   10× 10×   10×           22× 22×   22×   17× 15× 14×     17×                  
var events = require('events');
var util = require('util');
var debug = require('debug')('home-controller:insteon:door');
 
function Door(id, insteon) {
  this.id = id;
  this.insteon = insteon;
 
  this.emitOnAck = true;
}
 
util.inherits(Door, events.EventEmitter);
 
 
Door.prototype.handleAllLinkBroadcast = function (group, cmd1, cmd2) {
 
  debug('Emitting BC command for device (%s) - group: %s, cmd1: %s, cmd2: %s', this.id, group, cmd1, cmd2);
  this.emit('command', group, cmd1, cmd2);
 
  switch (group) {
  case 1:
    if(cmd1 === '11') {
      this.emit('opened');
    } else if(cmd1 === '13') {
      this.emit('closed');
    } else {
      debug('No event for command - %s, group - %s', cmd1, group);
    }
    break;
  case 2:
    this.emit('closed');
    break;
  case 4:
    this.emit('heartbeat');
    if(cmd1 === '11') {
      this.emit('opened');
    } else if(cmd1 === '13') {
      this.emit('closed');
    } else {
      debug('No event for command - %s, group - %s', cmd1, group);
    }
    break;
  default:
    debug('No event for command - %s, group - %s', cmd1, group);
  }
};
 
 
module.exports = Door;