Skip to content

Commit b84f8b9

Browse files
committed
Minor UI improvements
### UPDATED - Types for `http` changed to `node:http` for better clarification. - Scripts will now leverage it's own class constructors (with the `no-new` override). - Settings UI sensor title design. ### FIXED - Settings page does not load in development mode.
1 parent 5634c79 commit b84f8b9

File tree

11 files changed

+142
-97
lines changed

11 files changed

+142
-97
lines changed

.eslintrc.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,17 @@
127127
}
128128
]
129129
}
130+
},
131+
{
132+
"files": [
133+
"./src/scripts/repl.ts",
134+
"./src/scripts/test-api.ts"
135+
],
136+
"rules": {
137+
"no-new": [
138+
"off"
139+
]
140+
}
130141
}
131142
]
132143
}

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.4.0",
4+
"version": "3.4.1",
55
"description": "Homebridge security system platform for ADT Pulse",
66
"main": "./build/index.js",
77
"exports": "./build/index.js",

src/config-ui/vite/src/pages/settings-sensors.tsx

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { Controller, useFieldArray, useWatch } from 'react-hook-form';
33

4+
import { styles } from '@/config-ui/vite/src/styles/pages/settings-sensors.js';
45
import type { SettingsSensorsGetSensorHeaderIndex, SettingsSensorsGetSensorHeaderReturns, SettingsSensorsProps } from '@/types/config-ui.d.ts';
56

67
/**
@@ -35,25 +36,40 @@ export default function SettingsSensors(props: SettingsSensorsProps) {
3536
const sensor = watch[index];
3637

3738
if (sensor === undefined) {
38-
return '';
39+
return {
40+
name: null,
41+
adtName: null,
42+
};
3943
}
4044

4145
const sensorName = sensor.name;
4246
const sensorAdtName = sensor.adtName;
4347

4448
if (sensorName && sensorAdtName) {
45-
return `${sensorName} (${sensorAdtName})`;
49+
return {
50+
name: sensorName,
51+
adtName: sensorAdtName,
52+
};
4653
}
4754

4855
if (sensorName) {
49-
return `${sensorName}`;
56+
return {
57+
name: sensorName,
58+
adtName: null,
59+
};
5060
}
5161

5262
if (sensorAdtName) {
53-
return `${sensorAdtName}`;
63+
return {
64+
name: null,
65+
adtName: sensorAdtName,
66+
};
5467
}
5568

56-
return 'Sensor';
69+
return {
70+
name: 'Sensor',
71+
adtName: null,
72+
};
5773
};
5874

5975
return (
@@ -77,7 +93,22 @@ export default function SettingsSensors(props: SettingsSensorsProps) {
7793
aria-expanded="false"
7894
aria-controls={`collapse-${sensor.id}`}
7995
>
80-
{getSensorHeader(index)}
96+
<div className="d-flex justify-content-between" style={styles.sensorHeader}>
97+
{
98+
(getSensorHeader(index).name !== null) ? (
99+
<span>
100+
{getSensorHeader(index).name}
101+
</span>
102+
) : null
103+
}
104+
{
105+
(getSensorHeader(index).adtName !== null) ? (
106+
<span className="text-secondary fst-italic">
107+
{getSensorHeader(index).adtName}
108+
</span>
109+
) : null
110+
}
111+
</div>
81112
</button>
82113
</div>
83114
<div id={`collapse-${sensor.id}`} className="accordion-collapse collapse" data-bs-parent="#accordion">

src/config-ui/vite/src/pages/settings.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export default function Settings(props: SettingsProps) {
5151
useEffect(() => {
5252
(async () => {
5353
if (homebridge === undefined) {
54+
setReady(true);
55+
5456
return;
5557
}
5658

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { Styles } from '@/types/config-ui.d.ts';
2+
3+
/**
4+
* Styles.
5+
*
6+
* @returns {Styles}
7+
*
8+
* @since 1.0.0
9+
*/
10+
export const styles: Styles = {
11+
sensorHeader: {
12+
width: '95%',
13+
},
14+
};

src/lib/utility.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ export function getAccessoryCategory(deviceCategory: GetAccessoryCategoryDeviceC
727727
* @since 1.0.0
728728
*/
729729
export function getDetectReportUrl(): GetDetectReportUrlReturns {
730-
return 'https://f4ds5bzvu2c2tmxc47bh.ntfy.mrjackyliang.com';
730+
return 'https://b4ch8ibuidp0wv68c3x9.ntfy.mrjackyliang.com';
731731
}
732732

733733
/**

src/scripts/repl.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import type {
2020
ADTPulseReplSetAuthInstanceReturns,
2121
ADTPulseReplSetAuthInstanceSubdomain,
2222
ADTPulseReplSetAuthInstanceUsername,
23-
ADTPulseReplStartReplReturns,
2423
} from '@/types/index.d.ts';
2524

2625
/**
@@ -54,16 +53,14 @@ class ADTPulseRepl {
5453
*
5554
* @since 1.0.0
5655
*/
57-
#replServer: ADTPulseReplReplServer;
56+
readonly #replServer: ADTPulseReplReplServer;
5857

5958
/**
60-
* ADT Pulse Repl - Start repl.
61-
*
62-
* @returns {ADTPulseReplStartReplReturns}
59+
* ADT Pulse Repl - Constructor.
6360
*
6461
* @since 1.0.0
6562
*/
66-
public async startRepl(): ADTPulseReplStartReplReturns {
63+
constructor() {
6764
ADTPulseRepl.displayStartupHeader();
6865
ADTPulseRepl.displayHelpMenu();
6966

@@ -356,5 +353,4 @@ class ADTPulseRepl {
356353
}
357354
}
358355

359-
const adtPulseRepl = new ADTPulseRepl();
360-
await adtPulseRepl.startRepl();
356+
new ADTPulseRepl();

src/scripts/test-api.ts

Lines changed: 63 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import type {
1919
ADTPulseTestPrintTestOutputReturns,
2020
ADTPulseTestSelectedConfigLocation,
2121
ADTPulseTestSelectedPlatform,
22-
ADTPulseTestStartTestReturns,
2322
ADTPulseTestZodParseResponse,
2423
} from '@/types/index.d.ts';
2524

@@ -57,83 +56,83 @@ class ADTPulseTest {
5756
#zodParseResponse: ADTPulseTestZodParseResponse;
5857

5958
/**
60-
* ADT Pulse Test - Start test.
61-
*
62-
* @returns {ADTPulseTestStartTestReturns}
59+
* ADT Pulse Test - Constructor.
6360
*
6461
* @since 1.0.0
6562
*/
66-
async startTest(): ADTPulseTestStartTestReturns {
67-
try {
68-
const userAcceptedDisclaimer = await ADTPulseTest.askQuestion('disclaimer');
69-
70-
if (!userAcceptedDisclaimer) {
71-
exit(0);
72-
}
73-
74-
// Used to pad the user input to the next line.
75-
console.info('\r');
63+
constructor() {
64+
(async () => {
65+
try {
66+
const userAcceptedDisclaimer = await ADTPulseTest.askQuestion('disclaimer');
7667

77-
const configFoundAndSet = this.findConfig();
68+
if (!userAcceptedDisclaimer) {
69+
exit(0);
70+
}
7871

79-
if (!configFoundAndSet || this.#selectedPlatform === undefined) {
80-
ADTPulseTest.printTestOutput(false);
72+
// Used to pad the user input to the next line.
73+
console.info('\r');
8174

82-
exit(1);
83-
}
75+
const configFoundAndSet = this.findConfig();
8476

85-
const instance = new ADTPulseAPI(
86-
this.#selectedPlatform,
87-
{
88-
debug: true,
89-
testMode: {
90-
enabled: true,
91-
},
92-
},
93-
);
94-
const instanceFunctions = [
95-
instance.login.bind(instance),
96-
instance.getGatewayInformation.bind(instance),
97-
instance.getPanelInformation.bind(instance),
98-
instance.getPanelStatus.bind(instance),
99-
instance.setPanelStatus.bind(instance, 'off', 'away', false),
100-
instance.setPanelStatus.bind(instance, 'away', 'stay', false),
101-
instance.setPanelStatus.bind(instance, 'stay', 'night', false),
102-
instance.setPanelStatus.bind(instance, 'night', 'off', false),
103-
instance.getSensorsInformation.bind(instance),
104-
instance.getSensorsStatus.bind(instance),
105-
instance.getOrbSecurityButtons.bind(instance),
106-
instance.performSyncCheck.bind(instance),
107-
instance.performKeepAlive.bind(instance),
108-
instance.logout.bind(instance),
109-
];
110-
111-
for (let i = 0; i < instanceFunctions.length; i += 1) {
112-
const response = await instanceFunctions[i]();
113-
114-
// If response is not successful, end the test.
115-
if (!response.success) {
77+
if (!configFoundAndSet || this.#selectedPlatform === undefined) {
11678
ADTPulseTest.printTestOutput(false);
11779

11880
exit(1);
11981
}
12082

121-
// Print success responses.
122-
console.info(util.inspect(response, {
123-
showHidden: false,
124-
depth: Infinity,
125-
colors: true,
126-
}));
127-
}
83+
const instance = new ADTPulseAPI(
84+
this.#selectedPlatform,
85+
{
86+
debug: true,
87+
testMode: {
88+
enabled: true,
89+
},
90+
},
91+
);
92+
const instanceFunctions = [
93+
instance.login.bind(instance),
94+
instance.getGatewayInformation.bind(instance),
95+
instance.getPanelInformation.bind(instance),
96+
instance.getPanelStatus.bind(instance),
97+
instance.setPanelStatus.bind(instance, 'off', 'away', false),
98+
instance.setPanelStatus.bind(instance, 'away', 'stay', false),
99+
instance.setPanelStatus.bind(instance, 'stay', 'night', false),
100+
instance.setPanelStatus.bind(instance, 'night', 'off', false),
101+
instance.getSensorsInformation.bind(instance),
102+
instance.getSensorsStatus.bind(instance),
103+
instance.getOrbSecurityButtons.bind(instance),
104+
instance.performSyncCheck.bind(instance),
105+
instance.performKeepAlive.bind(instance),
106+
instance.logout.bind(instance),
107+
];
108+
109+
for (let i = 0; i < instanceFunctions.length; i += 1) {
110+
const response = await instanceFunctions[i]();
111+
112+
// If response is not successful, end the test.
113+
if (!response.success) {
114+
ADTPulseTest.printTestOutput(false);
115+
116+
exit(1);
117+
}
128118

129-
ADTPulseTest.printTestOutput(true);
119+
// Print success responses.
120+
console.info(util.inspect(response, {
121+
showHidden: false,
122+
depth: Infinity,
123+
colors: true,
124+
}));
125+
}
130126

131-
exit(0);
132-
} catch {
133-
ADTPulseTest.printTestOutput(false);
127+
ADTPulseTest.printTestOutput(true);
134128

135-
exit(1);
136-
}
129+
exit(0);
130+
} catch {
131+
ADTPulseTest.printTestOutput(false);
132+
133+
exit(1);
134+
}
135+
})();
137136
}
138137

139138
/**
@@ -294,5 +293,4 @@ class ADTPulseTest {
294293
}
295294
}
296295

297-
const instance = new ADTPulseTest();
298-
await instance.startTest();
296+
new ADTPulseTest();

src/types/config-ui.d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,14 @@ export type SettingsSensorsProps = {
344344
*/
345345
export type SettingsSensorsGetSensorHeaderIndex = number;
346346

347-
export type SettingsSensorsGetSensorHeaderReturns = string;
347+
export type SettingsSensorsGetSensorHeaderReturnsName = string | null;
348+
349+
export type SettingsSensorsGetSensorHeaderReturnsAdtName = string | null;
350+
351+
export type SettingsSensorsGetSensorHeaderReturns = {
352+
name: SettingsSensorsGetSensorHeaderReturnsName;
353+
adtName: SettingsSensorsGetSensorHeaderReturnsAdtName;
354+
};
348355

349356
/**
350357
* Setup.

src/types/index.d.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,13 +1304,6 @@ export type ADTPulseReplSetAuthInstancePassword = unknown;
13041304

13051305
export type ADTPulseReplSetAuthInstanceReturns = void;
13061306

1307-
/**
1308-
* ADT Pulse Repl - Start repl.
1309-
*
1310-
* @since 1.0.0
1311-
*/
1312-
export type ADTPulseReplStartReplReturns = Promise<void>;
1313-
13141307
/**
13151308
* ADT Pulse Test - Ask question.
13161309
*
@@ -1356,13 +1349,6 @@ export type ADTPulseTestSelectedConfigLocation = string | undefined;
13561349
*/
13571350
export type ADTPulseTestSelectedPlatform = Config | undefined;
13581351

1359-
/**
1360-
* ADT Pulse Test - Start test.
1361-
*
1362-
* @since 1.0.0
1363-
*/
1364-
export type ADTPulseTestStartTestReturns = Promise<void>;
1365-
13661352
/**
13671353
* ADT Pulse Test - Zod parse response.
13681354
*

0 commit comments

Comments
 (0)