UNPKG

homebridge-gsh

Version:
608 lines 19 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const hap_types_1 = require("../hap-types"); const security_system_1 = require("./security-system"); const securitySystem = new security_system_1.SecuritySystem(); describe('securitySystem', () => { describe('sync message', () => { it('securitySystem with On/Off only', () => __awaiter(void 0, void 0, void 0, function* () { const response = securitySystem.sync(securitySystemServiceOnOff); expect(response).toBeDefined(); expect(response.type).toBe('action.devices.types.SECURITYSYSTEM'); expect(response.traits).toContain('action.devices.traits.ArmDisarm'); expect(response.traits).not.toContain('action.devices.traits.Brightness'); expect(response.traits).not.toContain('action.devices.traits.ColorSetting'); expect(response.attributes).toBeDefined(); expect(response.name).toBeDefined(); })); }); describe('query message', () => { it('securitySystem with On/Off only', () => __awaiter(void 0, void 0, void 0, function* () { const response = securitySystem.query(securitySystemServiceOnOff); expect(response).toBeDefined(); expect(response.online).toBeDefined(); expect(response.isArmed).toBeDefined(); })); }); describe('execute message', () => { it('Arm', () => __awaiter(void 0, void 0, void 0, function* () { const response = yield securitySystem.execute(securitySystemServiceOnOff, commandArm); expect(response).toBeDefined(); expect(response.ids).toBeDefined(); expect(response.status).toBe('SUCCESS'); })); it('Disarm', () => __awaiter(void 0, void 0, void 0, function* () { const response = yield securitySystem.execute(securitySystemServiceOnOff, commandDisarm); expect(response).toBeDefined(); expect(response.ids).toBeDefined(); expect(response.status).toBe('SUCCESS'); })); it('securitySystem with On/Off only - commandMalformed', () => __awaiter(void 0, void 0, void 0, function* () { const response = yield securitySystem.execute(securitySystemServiceOnOff, commandMalformed); expect(response).toBeDefined(); expect(response.ids).toBeDefined(); expect(response.status).toBe('ERROR'); })); it('securitySystem with On/Off only - commandIncorrectCommand', () => __awaiter(void 0, void 0, void 0, function* () { const response = yield securitySystem.execute(securitySystemServiceOnOff, commandIncorrectCommand); expect(response).toBeDefined(); expect(response.ids).toBeDefined(); expect(response.status).toBe('ERROR'); })); it('securitySystem with On/Off only - Error', () => __awaiter(void 0, void 0, void 0, function* () { expect.assertions(1); securitySystemServiceOnOff.serviceCharacteristics[0].setValue = setValueError; expect(securitySystem.execute(securitySystemServiceOnOff, commandArm)).rejects.toThrow('Error setting value'); })); }); describe('2 factor authentication', () => { it('twoFactorRequired should be set', () => __awaiter(void 0, void 0, void 0, function* () { expect(securitySystem.twoFactorRequired).toBeDefined(); expect(securitySystem.twoFactorRequired).toBe(true); })); it('Arm - does not request PIN', () => __awaiter(void 0, void 0, void 0, function* () { const response = yield securitySystem.is2faRequired(commandArm); expect(response).toBeDefined(); expect(response).toBe(false); })); it('Disarm - must request PIN', () => __awaiter(void 0, void 0, void 0, function* () { const response = yield securitySystem.is2faRequired(commandDisarm); expect(response).toBeDefined(); expect(response).toBe(true); })); }); }); function sleep(ms) { return __awaiter(this, void 0, void 0, function* () { return new Promise(resolve => setTimeout(resolve, ms)); }); } const setValue = function (value) { return __awaiter(this, void 0, void 0, function* () { const result = { aid: 1, iid: 1, uuid: '00000025-0000-1000-8000-0026BB765291', type: 'On', serviceType: 'SecuritySystem', serviceName: 'Trailer Step', description: 'On', value: 0, format: 'bool', perms: [ 'ev', 'pr', 'pw', ], canRead: true, canWrite: true, ev: true, }; return result; }); }; const setValueError = function (value) { return __awaiter(this, void 0, void 0, function* () { throw new Error('Error setting value'); const result = { aid: 1, iid: 1, uuid: '00000025-0000-1000-8000-0026BB765291', type: 'On', serviceType: 'Lightbulb', serviceName: 'Trailer Step', description: 'On', value: 0, format: 'bool', perms: [ 'ev', 'pr', 'pw', ], canRead: true, canWrite: true, ev: true, }; return result; }); }; const getValue = function () { return __awaiter(this, void 0, void 0, function* () { const result = { aid: 1, iid: 1, uuid: '00000025-0000-1000-8000-0026BB765291', type: 'On', serviceType: 'SecuritySystem', serviceName: 'Trailer Step', description: 'On', value: 0, format: 'bool', perms: [ 'ev', 'pr', 'pw', ], canRead: true, canWrite: true, ev: true, }; return result; }); }; const refreshCharacteristics = function () { return __awaiter(this, void 0, void 0, function* () { return securitySystemServiceOnOff; }); }; const setCharacteristic = function (value) { return __awaiter(this, void 0, void 0, function* () { const result = { aid: 1, iid: 1, uuid: '00000025-0000-1000-8000-0026BB765291', type: 'On', serviceType: 'SecuritySystem', serviceName: 'Trailer Step', description: 'On', value: 0, format: 'bool', perms: [ 'ev', 'pr', 'pw', ], canRead: true, canWrite: true, ev: true, }; return securitySystemServiceOnOff; }); }; const getCharacteristic = function () { const result = { aid: 1, iid: 1, uuid: '00000025-0000-1000-8000-0026BB765291', type: 'On', serviceType: 'SecuritySystem', serviceName: 'Trailer Step', description: 'On', value: 0, format: 'bool', perms: [ 'ev', 'pr', 'pw', ], canRead: true, canWrite: true, ev: true, }; return result; }; const securitySystemServiceOnOff = { aid: 13, iid: 8, uuid: '00000043-0000-1000-8000-0026BB765291', type: 'SecuritySystem', humanType: 'SecuritySystem', serviceName: 'Shed Light', serviceCharacteristics: [ { aid: 13, iid: 11, uuid: hap_types_1.Characteristic.SecuritySystemTargetState, type: 'SecuritySystemTargetState', serviceType: 'SecuritySystem', serviceName: 'Shed Light', description: 'Configured Name', value: 1, format: 'string', perms: ['ev', 'pr', 'pw'], unit: undefined, maxValue: undefined, minValue: undefined, minStep: undefined, canRead: true, canWrite: true, ev: true, setValue, getValue, }, { aid: 13, iid: 11, uuid: hap_types_1.Characteristic.SecuritySystemCurrentState, type: 'SecuritySystemCurrentState', serviceType: 'SecuritySystem', serviceName: 'Shed Light', description: 'Configured Name', value: 1, format: 'string', perms: ['ev', 'pr', 'pw'], unit: undefined, maxValue: undefined, minValue: undefined, minStep: undefined, canRead: true, canWrite: true, ev: true, setValue, getValue, }, { aid: 13, iid: 10, uuid: '000000B0-0000-1000-8000-0026BB765291', type: 'Active', serviceType: 'SecuritySystem', serviceName: 'Shed Light', description: 'On', value: 0, format: 'bool', perms: ['ev', 'pr', 'pw'], unit: undefined, maxValue: undefined, minValue: undefined, minStep: undefined, canRead: true, canWrite: true, ev: true, setValue, getValue, }, { aid: 13, iid: 10, uuid: '0000007C-0000-1000-8000-0026BB765291', type: 'TargetPosition', serviceType: 'SecuritySystem', serviceName: 'Shed Light', description: 'On', value: 0, format: 'bool', perms: ['ev', 'pr', 'pw'], unit: undefined, maxValue: undefined, minValue: undefined, minStep: undefined, canRead: true, canWrite: true, ev: true, setValue, getValue, }, { aid: 13, iid: 10, uuid: '0000006D-0000-1000-8000-0026BB765291', type: 'CurrentPosition', serviceType: 'SecuritySystem', serviceName: 'Shed Light', description: 'On', value: 0, format: 'bool', perms: ['ev', 'pr', 'pw'], unit: undefined, maxValue: undefined, minValue: undefined, minStep: undefined, canRead: true, canWrite: true, ev: true, setValue, getValue, }, { aid: 13, iid: 11, uuid: '000000E3-0000-1000-8000-0026BB765291', type: 'ConfiguredName', serviceType: 'SecuritySystem', serviceName: 'Shed Light', description: 'Configured Name', value: 'Shed Light', format: 'string', perms: ['ev', 'pr', 'pw'], unit: undefined, maxValue: undefined, minValue: undefined, minStep: undefined, canRead: true, canWrite: true, ev: true, setValue, getValue, }, { aid: 13, iid: 11, uuid: hap_types_1.Characteristic.LockCurrentState, type: 'LockCurrentState', serviceType: 'SecuritySystem', serviceName: 'Shed Light', description: 'Configured Name', value: 1, format: 'string', perms: ['ev', 'pr', 'pw'], unit: undefined, maxValue: undefined, minValue: undefined, minStep: undefined, canRead: true, canWrite: true, ev: true, setValue, getValue, }, ], accessoryInformation: { 'Manufacturer': 'Tasmota', 'Model': 'WiOn', 'Name': 'Shed Light', 'Serial Number': '02231D-jessie', 'Firmware Revision': '9.5.0tasmota', }, values: { On: 0, ConfiguredName: 'Shed Light' }, linked: undefined, instance: { name: 'homebridge', username: '1C:22:3D:E3:CF:34', ipAddress: '192.168.1.11', port: 46283, connectionFailedCount: 0, services: [], configurationNumber: 1, }, uniqueId: '664195d5556f1e0b424ed32bcd863ec8954c76f8ab81cc399f0e24f8827806d1', refreshCharacteristics, setCharacteristic, getCharacteristic, }; const commandOnOff = { devices: [ { customData: { aid: 75, iid: 8, instanceIpAddress: '192.168.1.11', instancePort: 46283, instanceUsername: '1C:22:3D:E3:CF:34', }, id: 'b9245954ec41632a14076df3bbb7336f756c17ca4b040914a593e14d652d5738', }, ], execution: [ { command: 'action.devices.commands.OnOff', params: { on: true, }, }, ], }; const commandOpenClose = { devices: [ { customData: { aid: 75, iid: 8, instanceIpAddress: '192.168.1.11', instancePort: 46283, instanceUsername: '1C:22:3D:E3:CF:34', }, id: 'b9245954ec41632a14076df3bbb7336f756c17ca4b040914a593e14d652d5738', }, ], execution: [ { command: 'action.devices.commands.OpenClose', params: { openPercent: 50, }, }, ], }; const commandMalformed = { devices: [ { customData: { aid: 75, iid: 8, instanceIpAddress: '192.168.1.11', instancePort: 46283, instanceUsername: '1C:22:3D:E3:CF:34', }, id: 'b9245954ec41632a14076df3bbb7336f756c17ca4b040914a593e14d652d5738', }, ], execution: [], }; const commandIncorrectCommand = { devices: [ { customData: { aid: 75, iid: 8, instanceIpAddress: '192.168.1.11', instancePort: 46283, instanceUsername: '1C:22:3D:E3:CF:34', }, id: 'b9245954ec41632a14076df3bbb7336f756c17ca4b040914a593e14d652d5738', }, ], execution: [ { command: 'action.devices.commands.notACommand', params: { on: true, }, }, ], }; const commandBrightness = { devices: [ { customData: { aid: 75, iid: 8, instanceIpAddress: '192.168.1.11', instancePort: 46283, instanceUsername: '1C:22:3D:E3:CF:34', }, id: 'b9245954ec41632a14076df3bbb7336f756c17ca4b040914a593e14d652d5738', }, ], execution: [ { command: 'action.devices.commands.OnOff', params: { on: true, }, }, ], }; const commandColorHSV = { devices: [ { customData: { aid: 75, iid: 8, instanceIpAddress: '192.168.1.11', instancePort: 46283, instanceUsername: '1C:22:3D:E3:CF:34', }, id: 'b9245954ec41632a14076df3bbb7336f756c17ca4b040914a593e14d652d5738', }, ], execution: [ { command: 'action.devices.commands.OnOff', params: { on: true, }, }, ], }; const commandColorTemperature = { devices: [ { customData: { aid: 75, iid: 8, instanceIpAddress: '192.168.1.11', instancePort: 46283, instanceUsername: '1C:22:3D:E3:CF:34', }, id: 'b9245954ec41632a14076df3bbb7336f756c17ca4b040914a593e14d652d5738', }, ], execution: [ { command: 'action.devices.commands.OnOff', params: { on: true, }, }, ], }; const commandLockUnlock = { devices: [ { customData: { aid: 75, iid: 8, instanceIpAddress: '192.168.1.11', instancePort: 46283, instanceUsername: '1C:22:3D:E3:CF:34', }, id: 'b9245954ec41632a14076df3bbb7336f756c17ca4b040914a593e14d652d5738', }, ], execution: [ { command: 'action.devices.commands.LockUnlock', params: { lock: false, }, }, ], }; const commandArm = { devices: [ { customData: { aid: 75, iid: 8, instanceIpAddress: '192.168.1.11', instancePort: 46283, instanceUsername: '1C:22:3D:E3:CF:34', }, id: 'b9245954ec41632a14076df3bbb7336f756c17ca4b040914a593e14d652d5738', }, ], execution: [ { command: 'action.devices.commands.ArmDisarm', params: { arm: true, armLevel: 1, }, }, ], }; const commandDisarm = { devices: [ { customData: { aid: 75, iid: 8, instanceIpAddress: '192.168.1.11', instancePort: 46283, instanceUsername: '1C:22:3D:E3:CF:34', }, id: 'b9245954ec41632a14076df3bbb7336f756c17ca4b040914a593e14d652d5738', }, ], execution: [ { command: 'action.devices.commands.ArmDisarm', params: { arm: false, armLevel: 1, cancel: true, }, }, ], }; //# sourceMappingURL=security-system.spec.js.map