All files / src/lifx/packets getRelayPower.js

90.9% Statements 10/11
60% Branches 3/5
100% Functions 1/1
90.9% Lines 10/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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    1x                   1x 1x 1x 1x   1x     1x 1x   1x     1x  
'use strict';
 
const Packet = {
  size: 1
};
 
/**
 * Converts the given packet specific object into a packet
 * @param  {Object} obj object with configuration data
 * @param  {Number} obj.relayIndex start zone index, between 0 and 255
 * @return {Buffer} packet
 */
Packet.toBuffer = function(obj) {
  const buf = Buffer.alloc(this.size);
  buf.fill(0);
  let offset = 0;
 
  Iif (typeof obj.relayIndex !== 'number' && obj.relayIndex < 0 || obj.relayIndex > 3) {
    throw new RangeError('Invalid relayIndex value given for getRelayPower LIFX packet, must be a number between 0 and 3');
  }
  buf.writeUInt8(obj.relayIndex, offset);
  offset += 1;
 
  return buf;
};
 
module.exports = Packet;