homebridge-adt-pulse 3.0.0-beta.4 → 3.0.0-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,173 @@
1
+ import chalk from 'chalk';
2
+ import repl from 'node:repl';
3
+ import { ADTPulse } from '../lib/api.js';
4
+ class ADTPulseRepl {
5
+ #api;
6
+ #replServer;
7
+ async startRepl() {
8
+ ADTPulseRepl.displayStartupHeader();
9
+ ADTPulseRepl.displayHelpMenu();
10
+ this.#replServer = repl.start({
11
+ ignoreUndefined: true,
12
+ prompt: '> ',
13
+ });
14
+ this.#replServer.context.repl = this;
15
+ this.#replServer.defineCommand('break', {
16
+ help: 'Sometimes you get stuck, this gets you out',
17
+ action() {
18
+ ADTPulseRepl.colorLog('error', 'The ".break" command is not allowed.');
19
+ this.displayPrompt();
20
+ },
21
+ });
22
+ this.#replServer.defineCommand('clear', {
23
+ help: 'Break, and also clear the local context',
24
+ action() {
25
+ ADTPulseRepl.colorLog('error', 'The ".clear" command is not allowed.');
26
+ this.displayPrompt();
27
+ },
28
+ });
29
+ this.#replServer.defineCommand('editor', {
30
+ help: 'Enter editor mode',
31
+ action() {
32
+ ADTPulseRepl.colorLog('error', 'The ".editor" command is not allowed.');
33
+ this.displayPrompt();
34
+ },
35
+ });
36
+ this.#replServer.defineCommand('help', {
37
+ help: 'Print this help message',
38
+ action() {
39
+ ADTPulseRepl.displayHelpHeader();
40
+ ADTPulseRepl.displayHelpMenu();
41
+ this.displayPrompt();
42
+ },
43
+ });
44
+ this.#replServer.defineCommand('load', {
45
+ help: 'Load JS from a file into the REPL session',
46
+ action() {
47
+ ADTPulseRepl.colorLog('error', 'The ".load" command is not allowed.');
48
+ this.displayPrompt();
49
+ },
50
+ });
51
+ this.#replServer.defineCommand('save', {
52
+ help: 'Save all evaluated commands in this REPL session to a file',
53
+ action() {
54
+ ADTPulseRepl.colorLog('error', 'The ".save" command is not allowed.');
55
+ this.displayPrompt();
56
+ },
57
+ });
58
+ }
59
+ setInstance(subdomain, username, password, fingerprint) {
60
+ if (subdomain !== 'portal' && subdomain !== 'portal-ca') {
61
+ ADTPulseRepl.colorLog('error', 'Invalid subdomain specified. Valid values are either "portal" or "portal-ca".');
62
+ return;
63
+ }
64
+ if (typeof username !== 'string' || username === '') {
65
+ ADTPulseRepl.colorLog('error', 'Username must be a string and cannot be empty.');
66
+ return;
67
+ }
68
+ if (typeof password !== 'string' || password === '') {
69
+ ADTPulseRepl.colorLog('error', 'Password must be a string and cannot be empty.');
70
+ return;
71
+ }
72
+ if (typeof fingerprint !== 'string' || fingerprint === '') {
73
+ ADTPulseRepl.colorLog('error', 'Fingerprint must be a string and cannot be empty.');
74
+ return;
75
+ }
76
+ this.#api = new ADTPulse({
77
+ platform: 'ADTPulse',
78
+ subdomain,
79
+ username,
80
+ password,
81
+ fingerprint,
82
+ sensors: [],
83
+ }, {
84
+ debug: true,
85
+ });
86
+ if (this.#replServer === undefined) {
87
+ ADTPulseRepl.colorLog('error', 'Failed to set context because "this.#replServer" is undefined.');
88
+ return;
89
+ }
90
+ this.#replServer.context.api = this.#api;
91
+ ADTPulseRepl.colorLog('info', 'Instance has been successfully set.');
92
+ ADTPulseRepl.colorLog('info', 'You may now use the available API methods to test the system!');
93
+ ADTPulseRepl.colorLog('info', '\n');
94
+ }
95
+ static colorLog(type, message) {
96
+ switch (type) {
97
+ case 'error':
98
+ console.error(chalk.redBright(message));
99
+ break;
100
+ case 'info':
101
+ console.info(chalk.greenBright(message));
102
+ break;
103
+ default:
104
+ break;
105
+ }
106
+ }
107
+ static displayHelpHeader() {
108
+ console.info([
109
+ chalk.cyanBright('########################################################'),
110
+ chalk.cyanBright('#### ADT Pulse for Homebridge Plugin REPL Help Menu ####'),
111
+ chalk.cyanBright('########################################################'),
112
+ '',
113
+ 'This is the help menu on how to use this REPL interface. If you have questions on how',
114
+ 'to use this, please refer to the documentation using the link below:',
115
+ '',
116
+ 'https://github.com/mrjackyliang/homebridge-adt-pulse',
117
+ ].join('\n'));
118
+ }
119
+ static displayHelpMenu() {
120
+ console.info([
121
+ '',
122
+ chalk.bold('Method parameter documentation:'),
123
+ ` {'portal' | 'portal-ca'} ${chalk.magentaBright('subdomain')} - Set the domain for either USA or Canada subscribers`,
124
+ ` {string} ${chalk.magentaBright('username')} - The username for logging in to ADT Pulse portal`,
125
+ ` {string} ${chalk.magentaBright('password')} - The password for logging in to ADT Pulse portal`,
126
+ ` {string} ${chalk.magentaBright('fingerprint')} - The fingerprint for logging in to ADT Pulse portal`,
127
+ ` {'arm' | 'night' | 'off' | 'stay'} ${chalk.magentaBright('armTo')} - Available methods to arm the system`,
128
+ '',
129
+ chalk.bold('Before you use the API, set the instance using this command:'),
130
+ ` ${chalk.yellowBright(`repl.setInstance(${chalk.magentaBright('subdomain')}, ${chalk.magentaBright('username')}, ${chalk.magentaBright('password')}, ${chalk.magentaBright('fingerprint')});`)}`,
131
+ '',
132
+ chalk.bold('Once an instance is set, interact with the portal using these methods:'),
133
+ ` ${chalk.yellowBright('await api.login();')}`,
134
+ ` ${chalk.yellowBright('await api.logout();')}`,
135
+ ` ${chalk.yellowBright('await api.getGatewayInformation();')}`,
136
+ ` ${chalk.yellowBright('await api.getPanelInformation();')}`,
137
+ ` ${chalk.yellowBright('await api.getPanelStatus();')}`,
138
+ ` ${chalk.yellowBright(`await api.setPanelStatus(${chalk.magentaBright('armTo')});`)}`,
139
+ ` ${chalk.yellowBright('await api.getSensorsInformation();')}`,
140
+ ` ${chalk.yellowBright('await api.getSensorsStatus();')}`,
141
+ ` ${chalk.yellowBright('await api.performSyncCheck();')}`,
142
+ ` ${chalk.yellowBright('await api.performKeepAlive();')}`,
143
+ ` ${chalk.yellowBright(' api.isAuthenticated();')}`,
144
+ '',
145
+ chalk.bold('You may also wrap the above methods with this to see the entire response:'),
146
+ ` ${chalk.yellowBright(`console.log(util.inspect(${chalk.magentaBright('replace me without the ending semi-colon')}, false, null, true));`)}`,
147
+ chalk.bold('A small reference for REPL commands:'),
148
+ ` ${chalk.yellowBright('.exit')}`,
149
+ ` ${chalk.yellowBright('.help')}`,
150
+ '',
151
+ ].join('\n'));
152
+ }
153
+ static displayStartupHeader() {
154
+ console.info([
155
+ chalk.cyanBright('##############################################################'),
156
+ chalk.cyanBright('#### ADT Pulse for Homebridge Plugin REPL ####'),
157
+ chalk.cyanBright('#### https://github.com/mrjackyliang/homebridge-adt-pulse ####'),
158
+ chalk.cyanBright('#### ####'),
159
+ chalk.cyanBright('#### Copyright (c) 2023 Jacky Liang. ISC License. ####'),
160
+ chalk.cyanBright('##############################################################'),
161
+ '',
162
+ 'Welcome to the REPL interface for ADT Pulse for Homebridge. This interface',
163
+ 'allows you to interact with the ADT Pulse portal via the included API and is designed',
164
+ `for advanced users only. ${chalk.redBright('PLEASE USE WITH CAUTION, NO WARRANTY IS PROVIDED.')}`,
165
+ '',
166
+ `${chalk.bold.yellowBright('NOTICE')}: The API gathers anonymous analytics to detect potential bugs or issues.`,
167
+ ' All personally identifiable information redacted. You will see exactly what will be sent out.',
168
+ ].join('\n'));
169
+ }
170
+ }
171
+ const adtPulseRepl = new ADTPulseRepl();
172
+ await adtPulseRepl.startRepl();
173
+ //# sourceMappingURL=repl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repl.js","sourceRoot":"","sources":["../../../src/scripts/repl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAuBxC,MAAM,YAAY;IAQhB,IAAI,CAAkB;IAStB,WAAW,CAAyB;IASpC,KAAK,CAAC,SAAS;QACb,YAAY,CAAC,oBAAoB,EAAE,CAAC;QACpC,YAAY,CAAC,eAAe,EAAE,CAAC;QAG/B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC;YAC5B,eAAe,EAAE,IAAI;YACrB,MAAM,EAA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KAAK,CAAC,YAAY,CAAC,4BAA4B,KAAK,CAAC,aAAa,CAAC,0CAA0C,CAAC,wBAAwB,CAAC,EAAE;YAChJ,KAAK,CAAC,IAAI,CAAC,sCAAsC,CAAC;YAClD,OAAO,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE;YACpC,OAAO,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE;YACpC,EAAE;SACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAChB,CAAC;IASO,MAAM,CAAC,oBAAoB;QACjC,OAAO,CAAC,IAAI,CAAC;YACX,KAAK,CAAC,UAAU,CAAC,gEAAgE,CAAC;YAClF,KAAK,CAAC,UAAU,CAAC,gEAAgE,CAAC;YAClF,KAAK,CAAC,UAAU,CAAC,gEAAgE,CAAC;YAClF,KAAK,CAAC,UAAU,CAAC,gEAAgE,CAAC;YAClF,KAAK,CAAC,UAAU,CAAC,gEAAgE,CAAC;YAClF,KAAK,CAAC,UAAU,CAAC,gEAAgE,CAAC;YAClF,EAAE;YACF,4EAA4E;YAC5E,uFAAuF;YACvF,4BAA4B,KAAK,CAAC,SAAS,CAAC,mDAAmD,CAAC,EAAE;YAClG,EAAE;YACF,GAAG,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,2EAA2E;YAC/G,uGAAuG;SACxG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAChB,CAAC;CACF;AAED,MAAM,YAAY,GAAG,IAAI,YAAY,EAAE,CAAC;AACxC,MAAM,YAAY,CAAC,SAAS,EAAE,CAAC"}
@@ -0,0 +1,171 @@
1
+ import chalk from 'chalk';
2
+ import _ from 'lodash';
3
+ import { readFileSync } from 'node:fs';
4
+ import os from 'node:os';
5
+ import { exit, stdin, stdout } from 'node:process';
6
+ import readline from 'node:readline';
7
+ import util from 'node:util';
8
+ import { ADTPulse } from '../lib/api.js';
9
+ import { platformConfig } from '../lib/schema.js';
10
+ import { debugLog, isForwardSlashOS } from '../lib/utility.js';
11
+ class ADTPulseTest {
12
+ #selectedConfigLocation;
13
+ #selectedPlatform;
14
+ async startTest() {
15
+ try {
16
+ const userAcceptedDisclaimer = await ADTPulseTest.askQuestion('disclaimer');
17
+ if (!userAcceptedDisclaimer) {
18
+ exit(0);
19
+ }
20
+ console.info('\r');
21
+ const configFoundAndSet = this.findConfig();
22
+ if (!configFoundAndSet || this.#selectedPlatform === undefined) {
23
+ ADTPulseTest.printTestOutput(false);
24
+ exit(1);
25
+ }
26
+ const instance = new ADTPulse(this.#selectedPlatform, {
27
+ debug: true,
28
+ testMode: {
29
+ enabled: true,
30
+ },
31
+ });
32
+ const instanceFunctions = [
33
+ instance.login.bind(instance),
34
+ instance.getGatewayInformation.bind(instance),
35
+ instance.getPanelInformation.bind(instance),
36
+ instance.getPanelStatus.bind(instance),
37
+ instance.setPanelStatus.bind(instance, 'away'),
38
+ instance.setPanelStatus.bind(instance, 'stay'),
39
+ instance.setPanelStatus.bind(instance, 'night'),
40
+ instance.setPanelStatus.bind(instance, 'off'),
41
+ instance.getSensorsInformation.bind(instance),
42
+ instance.getSensorsStatus.bind(instance),
43
+ instance.performSyncCheck.bind(instance),
44
+ instance.performKeepAlive.bind(instance),
45
+ instance.logout.bind(instance),
46
+ ];
47
+ for (let i = 0; i < instanceFunctions.length; i += 1) {
48
+ const response = await instanceFunctions[i]();
49
+ if (!response.success) {
50
+ ADTPulseTest.printTestOutput(false);
51
+ exit(1);
52
+ }
53
+ console.info(util.inspect(response, {
54
+ showHidden: false,
55
+ depth: Infinity,
56
+ colors: true,
57
+ }));
58
+ }
59
+ ADTPulseTest.printTestOutput(true);
60
+ exit(0);
61
+ }
62
+ catch {
63
+ ADTPulseTest.printTestOutput(false);
64
+ exit(1);
65
+ }
66
+ }
67
+ findConfig() {
68
+ const possibleLocations = [
69
+ ...(isForwardSlashOS()) ? [
70
+ '/homebridge/config.json',
71
+ '/var/lib/homebridge/config.json',
72
+ `${os.homedir()}/.homebridge/config.json`,
73
+ ] : [],
74
+ ...(!isForwardSlashOS()) ? [
75
+ `${os.homedir()}\\.homebridge\\config.json`,
76
+ ] : [],
77
+ ];
78
+ for (let i = 0; i < possibleLocations.length; i += 1) {
79
+ if (this.#selectedConfigLocation !== undefined && this.#selectedPlatform !== undefined) {
80
+ break;
81
+ }
82
+ debugLog(null, 'test-api.ts', 'info', `Attempt ${i + 1}: Finding the Homebridge config file in "${possibleLocations[i]}"`);
83
+ try {
84
+ const rawFile = readFileSync(possibleLocations[i], 'utf-8');
85
+ const parsedFile = JSON.parse(rawFile);
86
+ const platforms = _.get(parsedFile, ['platforms']);
87
+ const adtPlatform = _.find(platforms, (platform) => _.get(platform, ['platform']) === 'ADTPulse');
88
+ if (adtPlatform !== undefined) {
89
+ const validAdtPlatform = platformConfig.safeParse(adtPlatform);
90
+ if (validAdtPlatform.success) {
91
+ this.#selectedConfigLocation = possibleLocations[i];
92
+ this.#selectedPlatform = validAdtPlatform.data;
93
+ }
94
+ }
95
+ }
96
+ catch {
97
+ this.#selectedConfigLocation = undefined;
98
+ this.#selectedPlatform = undefined;
99
+ }
100
+ }
101
+ if (this.#selectedConfigLocation === undefined || this.#selectedPlatform === undefined) {
102
+ debugLog(null, 'test-api.ts', 'error', 'Unable to find a parsable Homebridge config file with a validated "ADTPulse" platform');
103
+ return false;
104
+ }
105
+ debugLog(null, 'test-api.ts', 'success', `Found valid Homebridge config in "${this.#selectedConfigLocation}"`);
106
+ return true;
107
+ }
108
+ static async askQuestion(mode) {
109
+ const rlInterface = readline.createInterface({
110
+ input: stdin,
111
+ output: stdout,
112
+ });
113
+ const questions = {
114
+ disclaimer: [
115
+ chalk.cyanBright('##############################################################'),
116
+ chalk.cyanBright('#### ADT Pulse for Homebridge Plugin Test ####'),
117
+ chalk.cyanBright('#### https://github.com/mrjackyliang/homebridge-adt-pulse ####'),
118
+ chalk.cyanBright('#### ####'),
119
+ chalk.cyanBright('#### Copyright (c) 2023 Jacky Liang. ISC License. ####'),
120
+ chalk.cyanBright('##############################################################'),
121
+ 'Before you begin, please make sure of the following:',
122
+ '',
123
+ '1. You have the proper authorization to carry out system testing.',
124
+ '2. You are currently ON THE PROPERTY where the test is being conducted.',
125
+ '3. You have disarmed the system and have >= 1 door/window open.',
126
+ '4. You have access to MyADT and have placed the system in test mode.',
127
+ '',
128
+ `${chalk.redBright('WARNING')}: If you DO NOT have access to MyADT or CANNOT place the system into`,
129
+ 'test mode, please DO NOT PROCEED. The author is NOT RESPONSIBLE if the test causes',
130
+ 'an accidental trigger or if ADT agents/local authorities become involved.',
131
+ '',
132
+ `${chalk.bold.yellowBright('NOTICE')}: The API gathers anonymous analytics to detect potential bugs or issues.`,
133
+ ' All personally identifiable information redacted. You will see exactly what will be sent out.',
134
+ '',
135
+ chalk.yellowBright('Type "I Agree" (without quotes) to fully acknowledge that you have read through'),
136
+ chalk.yellowBright('and understood the instructions, and agree to the disclaimer above ...'),
137
+ '➜ ',
138
+ ].join('\n'),
139
+ };
140
+ return new Promise((resolve) => {
141
+ rlInterface.question(questions[mode], (input) => {
142
+ if (input !== 'I Agree') {
143
+ resolve(false);
144
+ }
145
+ resolve(true);
146
+ });
147
+ });
148
+ }
149
+ static printTestOutput(isSuccess) {
150
+ if (!isSuccess) {
151
+ console.info([
152
+ '',
153
+ chalk.redBright('########################################################################'),
154
+ chalk.redBright('##### Test has failed! Please check the error response #####'),
155
+ chalk.redBright('##### above, attempt to resolve them, then run this tester again #####'),
156
+ chalk.redBright('########################################################################'),
157
+ ].join('\n'));
158
+ return;
159
+ }
160
+ console.info([
161
+ '',
162
+ chalk.greenBright('########################################################################'),
163
+ chalk.greenBright('##### Test has completed! If you find my plugin useful #####'),
164
+ chalk.greenBright('##### please consider donating to my efforts via GitHub Sponsors #####'),
165
+ chalk.greenBright('########################################################################'),
166
+ ].join('\n'));
167
+ }
168
+ }
169
+ const instance = new ADTPulseTest();
170
+ await instance.startTest();
171
+ //# sourceMappingURL=test-api.js.map
@@ -0,0 +1 @@
1
+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