Skip to content

Commit b2a137d

Browse files
committed
Improved "test-api" script
### UPDATED - The "test-api" script will now show errors from `zod` if your configuration failed to parse. - Clarify the error message better if plugin detects an invalid configuration. v3.1.8
1 parent e533d02 commit b2a137d

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "homebridge-adt-pulse",
33
"displayName": "Homebridge ADT Pulse",
4-
"version": "3.1.7",
4+
"version": "3.1.8",
55
"description": "Homebridge security system platform for ADT Pulse",
66
"main": "./build/index.js",
77
"exports": "./build/index.js",

src/lib/platform.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ export class ADTPulsePlatform implements ADTPulsePlatformPlugin {
234234
// Check for a valid platform configuration before initializing.
235235
if (!parsedConfig.success) {
236236
this.#log.error('Plugin is unable to initialize due to an invalid platform configuration.');
237-
this.#log.warn('If you just upgraded from v2 to v3 / v3.1, please update your configuration structure.');
237+
this.#log.warn('If you just upgraded from "v2 to v3" or from "v3 to v3.1", please update your configuration.');
238+
this.#log.warn('Carefully observe the error below. The answer you are looking for is there.');
238239
stackTracer('zod-error', parsedConfig.error.errors);
239240

240241
return;

src/scripts/test-api.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import util from 'node:util';
88

99
import { ADTPulse } from '@/lib/api.js';
1010
import { platformConfig } from '@/lib/schema.js';
11-
import { debugLog, isForwardSlashOS } from '@/lib/utility.js';
11+
import { debugLog, isForwardSlashOS, stackTracer } from '@/lib/utility.js';
1212
import type {
1313
ADTPulseTestAskQuestionMode,
1414
ADTPulseTestAskQuestionReturns,
@@ -20,6 +20,7 @@ import type {
2020
ADTPulseTestSelectedConfigLocation,
2121
ADTPulseTestSelectedPlatform,
2222
ADTPulseTestStartTestReturns,
23+
ADTPulseTestZodParseResponse,
2324
} from '@/types/index.d.ts';
2425

2526
/**
@@ -46,6 +47,15 @@ class ADTPulseTest {
4647
*/
4748
#selectedPlatform: ADTPulseTestSelectedPlatform;
4849

50+
/**
51+
* ADT Pulse Test - Zod parse response.
52+
*
53+
* @private
54+
*
55+
* @since 1.0.0
56+
*/
57+
#zodParseResponse: ADTPulseTestZodParseResponse;
58+
4959
/**
5060
* ADT Pulse Test - Start test.
5161
*
@@ -163,6 +173,9 @@ class ADTPulseTest {
163173
if (adtPlatform !== undefined) {
164174
const validAdtPlatform = platformConfig.safeParse(adtPlatform);
165175

176+
// Set this to the instance in case "zod" parse failed.
177+
this.#zodParseResponse = validAdtPlatform;
178+
166179
if (validAdtPlatform.success) {
167180
this.#selectedConfigLocation = possibleLocations[i];
168181
this.#selectedPlatform = validAdtPlatform.data;
@@ -177,6 +190,12 @@ class ADTPulseTest {
177190
if (this.#selectedConfigLocation === undefined || this.#selectedPlatform === undefined) {
178191
debugLog(null, 'test-api.ts', 'error', 'Unable to find a parsable Homebridge config file with a validated "ADTPulse" platform');
179192

193+
if (this.#zodParseResponse !== undefined) {
194+
debugLog(null, 'test-api.ts', 'warn', 'If you just upgraded from "v2 to v3" or from "v3 to v3.1", please update your configuration');
195+
debugLog(null, 'test-api.ts', 'warn', 'Carefully observe the error below. The answer you are looking for is there');
196+
stackTracer('zod-error', this.#zodParseResponse);
197+
}
198+
180199
return false;
181200
}
182201

src/types/index.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,15 @@ export type ADTPulseTestSelectedPlatform = Config | undefined;
10671067
*/
10681068
export type ADTPulseTestStartTestReturns = Promise<void>;
10691069

1070+
/**
1071+
* ADT Pulse Test - Zod parse response.
1072+
*
1073+
* @private
1074+
*
1075+
* @since 1.0.0
1076+
*/
1077+
export type ADTPulseTestZodParseResponse = z.SafeParseReturnType<any, any> | undefined;
1078+
10701079
/**
10711080
* Clear html line break.
10721081
*

0 commit comments

Comments
 (0)