All files / src/commands info.ts

58.33% Statements 14/24
25% Branches 1/4
50% Functions 3/6
63.64% Lines 14/22
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 431x   1x 1x 1x   1x     1x 1x       1x 3x   3x 3x 3x 3x         1x                                  
import { Command, CommandType } from './command';
 
export const AccessoryInfoService = '180A';
export const FirmwareVersionCharacteristic = '2A28';
export const SerialNumberCharacteristic = '2A25';
 
export class GetVersionCommand extends Command<number> {
 
  constructor() {
    super(AccessoryInfoService, FirmwareVersionCharacteristic, (encoder) => {}, CommandType.read);
    this.name = "GetVersion";
  }
 
  
  parseResponse = (buffer: Buffer): number => {
    Iif (!buffer) { throw new Error("No response body"); }
 
    const uint8array: Uint8Array = buffer;
    const values = Array.from(uint8array);
    const number = parseInt(String.fromCharCode(... values));
    return number;
  }
  
}
 
export class GetSerialNumberCommand extends Command<string> {
 
  constructor() {
    super(AccessoryInfoService, SerialNumberCharacteristic, (encoder) => {}, CommandType.read);
    this.name = "GetSerialNumber";
  }
 
  parseResponse = (buffer: Buffer): string => {
    if (!buffer) { throw new Error("No response body"); }
 
    const uint8array: Uint8Array = buffer;
    const values = Array.from(uint8array);
    const str = String.fromCharCode(... values);
    return str;
  }
  
}