Skip to content

Commit

Permalink
Minor UI improvements
Browse files Browse the repository at this point in the history
### 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.
  • Loading branch information
mrjackyliang committed Sep 12, 2024
1 parent 5634c79 commit b84f8b9
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 97 deletions.
11 changes: 11 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,17 @@
}
]
}
},
{
"files": [
"./src/scripts/repl.ts",
"./src/scripts/test-api.ts"
],
"rules": {
"no-new": [
"off"
]
}
}
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "homebridge-adt-pulse",
"displayName": "Homebridge ADT Pulse",
"version": "3.4.0",
"version": "3.4.1",
"description": "Homebridge security system platform for ADT Pulse",
"main": "./build/index.js",
"exports": "./build/index.js",
Expand Down
43 changes: 37 additions & 6 deletions src/config-ui/vite/src/pages/settings-sensors.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { Controller, useFieldArray, useWatch } from 'react-hook-form';

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

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

if (sensor === undefined) {
return '';
return {
name: null,
adtName: null,
};
}

const sensorName = sensor.name;
const sensorAdtName = sensor.adtName;

if (sensorName && sensorAdtName) {
return `${sensorName} (${sensorAdtName})`;
return {
name: sensorName,
adtName: sensorAdtName,
};
}

if (sensorName) {
return `${sensorName}`;
return {
name: sensorName,
adtName: null,
};
}

if (sensorAdtName) {
return `${sensorAdtName}`;
return {
name: null,
adtName: sensorAdtName,
};
}

return 'Sensor';
return {
name: 'Sensor',
adtName: null,
};
};

return (
Expand All @@ -77,7 +93,22 @@ export default function SettingsSensors(props: SettingsSensorsProps) {
aria-expanded="false"
aria-controls={`collapse-${sensor.id}`}
>
{getSensorHeader(index)}
<div className="d-flex justify-content-between" style={styles.sensorHeader}>
{
(getSensorHeader(index).name !== null) ? (
<span>
{getSensorHeader(index).name}
</span>
) : null
}
{
(getSensorHeader(index).adtName !== null) ? (
<span className="text-secondary fst-italic">
{getSensorHeader(index).adtName}
</span>
) : null
}
</div>
</button>
</div>
<div id={`collapse-${sensor.id}`} className="accordion-collapse collapse" data-bs-parent="#accordion">
Expand Down
2 changes: 2 additions & 0 deletions src/config-ui/vite/src/pages/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export default function Settings(props: SettingsProps) {
useEffect(() => {
(async () => {
if (homebridge === undefined) {
setReady(true);

return;
}

Expand Down
14 changes: 14 additions & 0 deletions src/config-ui/vite/src/styles/pages/settings-sensors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { Styles } from '@/types/config-ui.d.ts';

/**
* Styles.
*
* @returns {Styles}
*
* @since 1.0.0
*/
export const styles: Styles = {
sensorHeader: {
width: '95%',
},
};
2 changes: 1 addition & 1 deletion src/lib/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ export function getAccessoryCategory(deviceCategory: GetAccessoryCategoryDeviceC
* @since 1.0.0
*/
export function getDetectReportUrl(): GetDetectReportUrlReturns {
return 'https://f4ds5bzvu2c2tmxc47bh.ntfy.mrjackyliang.com';
return 'https://b4ch8ibuidp0wv68c3x9.ntfy.mrjackyliang.com';
}

/**
Expand Down
12 changes: 4 additions & 8 deletions src/scripts/repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import type {
ADTPulseReplSetAuthInstanceReturns,
ADTPulseReplSetAuthInstanceSubdomain,
ADTPulseReplSetAuthInstanceUsername,
ADTPulseReplStartReplReturns,
} from '@/types/index.d.ts';

/**
Expand Down Expand Up @@ -54,16 +53,14 @@ class ADTPulseRepl {
*
* @since 1.0.0
*/
#replServer: ADTPulseReplReplServer;
readonly #replServer: ADTPulseReplReplServer;

/**
* ADT Pulse Repl - Start repl.
*
* @returns {ADTPulseReplStartReplReturns}
* ADT Pulse Repl - Constructor.
*
* @since 1.0.0
*/
public async startRepl(): ADTPulseReplStartReplReturns {
constructor() {
ADTPulseRepl.displayStartupHeader();
ADTPulseRepl.displayHelpMenu();

Expand Down Expand Up @@ -356,5 +353,4 @@ class ADTPulseRepl {
}
}

const adtPulseRepl = new ADTPulseRepl();
await adtPulseRepl.startRepl();
new ADTPulseRepl();
128 changes: 63 additions & 65 deletions src/scripts/test-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import type {
ADTPulseTestPrintTestOutputReturns,
ADTPulseTestSelectedConfigLocation,
ADTPulseTestSelectedPlatform,
ADTPulseTestStartTestReturns,
ADTPulseTestZodParseResponse,
} from '@/types/index.d.ts';

Expand Down Expand Up @@ -57,83 +56,83 @@ class ADTPulseTest {
#zodParseResponse: ADTPulseTestZodParseResponse;

/**
* ADT Pulse Test - Start test.
*
* @returns {ADTPulseTestStartTestReturns}
* ADT Pulse Test - Constructor.
*
* @since 1.0.0
*/
async startTest(): ADTPulseTestStartTestReturns {
try {
const userAcceptedDisclaimer = await ADTPulseTest.askQuestion('disclaimer');

if (!userAcceptedDisclaimer) {
exit(0);
}

// Used to pad the user input to the next line.
console.info('\r');
constructor() {
(async () => {
try {
const userAcceptedDisclaimer = await ADTPulseTest.askQuestion('disclaimer');

const configFoundAndSet = this.findConfig();
if (!userAcceptedDisclaimer) {
exit(0);
}

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

exit(1);
}
const configFoundAndSet = this.findConfig();

const instance = new ADTPulseAPI(
this.#selectedPlatform,
{
debug: true,
testMode: {
enabled: true,
},
},
);
const instanceFunctions = [
instance.login.bind(instance),
instance.getGatewayInformation.bind(instance),
instance.getPanelInformation.bind(instance),
instance.getPanelStatus.bind(instance),
instance.setPanelStatus.bind(instance, 'off', 'away', false),
instance.setPanelStatus.bind(instance, 'away', 'stay', false),
instance.setPanelStatus.bind(instance, 'stay', 'night', false),
instance.setPanelStatus.bind(instance, 'night', 'off', false),
instance.getSensorsInformation.bind(instance),
instance.getSensorsStatus.bind(instance),
instance.getOrbSecurityButtons.bind(instance),
instance.performSyncCheck.bind(instance),
instance.performKeepAlive.bind(instance),
instance.logout.bind(instance),
];

for (let i = 0; i < instanceFunctions.length; i += 1) {
const response = await instanceFunctions[i]();

// If response is not successful, end the test.
if (!response.success) {
if (!configFoundAndSet || this.#selectedPlatform === undefined) {
ADTPulseTest.printTestOutput(false);

exit(1);
}

// Print success responses.
console.info(util.inspect(response, {
showHidden: false,
depth: Infinity,
colors: true,
}));
}
const instance = new ADTPulseAPI(
this.#selectedPlatform,
{
debug: true,
testMode: {
enabled: true,
},
},
);
const instanceFunctions = [
instance.login.bind(instance),
instance.getGatewayInformation.bind(instance),
instance.getPanelInformation.bind(instance),
instance.getPanelStatus.bind(instance),
instance.setPanelStatus.bind(instance, 'off', 'away', false),
instance.setPanelStatus.bind(instance, 'away', 'stay', false),
instance.setPanelStatus.bind(instance, 'stay', 'night', false),
instance.setPanelStatus.bind(instance, 'night', 'off', false),
instance.getSensorsInformation.bind(instance),
instance.getSensorsStatus.bind(instance),
instance.getOrbSecurityButtons.bind(instance),
instance.performSyncCheck.bind(instance),
instance.performKeepAlive.bind(instance),
instance.logout.bind(instance),
];

for (let i = 0; i < instanceFunctions.length; i += 1) {
const response = await instanceFunctions[i]();

// If response is not successful, end the test.
if (!response.success) {
ADTPulseTest.printTestOutput(false);

exit(1);
}

ADTPulseTest.printTestOutput(true);
// Print success responses.
console.info(util.inspect(response, {
showHidden: false,
depth: Infinity,
colors: true,
}));
}

exit(0);
} catch {
ADTPulseTest.printTestOutput(false);
ADTPulseTest.printTestOutput(true);

exit(1);
}
exit(0);
} catch {
ADTPulseTest.printTestOutput(false);

exit(1);
}
})();
}

/**
Expand Down Expand Up @@ -294,5 +293,4 @@ class ADTPulseTest {
}
}

const instance = new ADTPulseTest();
await instance.startTest();
new ADTPulseTest();
9 changes: 8 additions & 1 deletion src/types/config-ui.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,14 @@ export type SettingsSensorsProps = {
*/
export type SettingsSensorsGetSensorHeaderIndex = number;

export type SettingsSensorsGetSensorHeaderReturns = string;
export type SettingsSensorsGetSensorHeaderReturnsName = string | null;

export type SettingsSensorsGetSensorHeaderReturnsAdtName = string | null;

export type SettingsSensorsGetSensorHeaderReturns = {
name: SettingsSensorsGetSensorHeaderReturnsName;
adtName: SettingsSensorsGetSensorHeaderReturnsAdtName;
};

/**
* Setup.
Expand Down
14 changes: 0 additions & 14 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1304,13 +1304,6 @@ export type ADTPulseReplSetAuthInstancePassword = unknown;

export type ADTPulseReplSetAuthInstanceReturns = void;

/**
* ADT Pulse Repl - Start repl.
*
* @since 1.0.0
*/
export type ADTPulseReplStartReplReturns = Promise<void>;

/**
* ADT Pulse Test - Ask question.
*
Expand Down Expand Up @@ -1356,13 +1349,6 @@ export type ADTPulseTestSelectedConfigLocation = string | undefined;
*/
export type ADTPulseTestSelectedPlatform = Config | undefined;

/**
* ADT Pulse Test - Start test.
*
* @since 1.0.0
*/
export type ADTPulseTestStartTestReturns = Promise<void>;

/**
* ADT Pulse Test - Zod parse response.
*
Expand Down
2 changes: 1 addition & 1 deletion src/types/shared.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { AxiosResponse } from 'axios';
import type { Logger } from 'homebridge';
import type http from 'http';
import type { JSDOM } from 'jsdom';
import type http from 'node:http';
import type { ErrorObject } from 'serialize-error';
import type { z } from 'zod';

Expand Down

0 comments on commit b84f8b9

Please sign in to comment.