Skip to content

Commit

Permalink
Minor enhancements
Browse files Browse the repository at this point in the history
### UPDATED
- Enhanced handling of session clean vs dirty `armState`.

### FIXED
- JSDoc `returns` comment for `copyToClipboard` function for the fingerprint retrival script.
- `ADTPulseTestZodParseResponse` type in `index.d.ts` had unnecessary `@private` parameter.
  • Loading branch information
mrjackyliang committed Feb 19, 2024
1 parent 67d0869 commit db078cc
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
2 changes: 1 addition & 1 deletion fingerprint/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let fingerprintResults;
* @param {Element} element - Element.
* @param {('fingerprint')} type - Type.
*
* @return {Promise<boolean>}
* @returns {Promise<boolean>}
*
* @since 1.0.0
*/
Expand Down
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.2.2",
"version": "3.2.3",
"description": "Homebridge security system platform for ADT Pulse",
"main": "./build/index.js",
"exports": "./build/index.js",
Expand Down
7 changes: 4 additions & 3 deletions src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
generateFakeReadyButtons,
generateHash,
isPortalSyncCode,
isSessionCleanState,
parseArmDisarmMessage,
parseDoSubmitHandlers,
parseOrbSecurityButtons,
Expand Down Expand Up @@ -2285,6 +2286,9 @@ export class ADTPulse {
rawHtml: sessions.axiosSummary.data,
});

// "armState" can be dirty without the plugin changing the state itself. Most likely when multiple users are logged in.
this.#session.isCleanState = isSessionCleanState(parsedOrbSecurityButtons);

if (this.#internal.debug) {
debugLog(this.#internal.logger, 'api.ts / ADTPulse.getOrbSecurityButtons()', 'success', `Successfully retrieved orb security buttons from "${this.#internal.baseUrl}"`);
}
Expand Down Expand Up @@ -2800,9 +2804,6 @@ export class ADTPulse {
forceArmRequired = forceArmResponse.info.forceArmRequired;
}

// After changing any arm state, the "armState" may be different from when you logged into the portal.
this.#session.isCleanState = false;

// Allow some time for the security orb buttons to refresh.
await sleep(this.#internal.waitTimeAfterArm);

Expand Down
23 changes: 23 additions & 0 deletions src/lib/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ import type {
IsPluginOutdatedReturns,
IsPortalSyncCodeSyncCode,
IsPortalSyncCodeTypeGuard,
IsSessionCleanStateOrbSecurityButtons,
IsSessionCleanStateReadyButton,
IsSessionCleanStateReturns,
IsUnknownDoSubmitHandlerCollectionHandlers,
IsUnknownDoSubmitHandlerCollectionReturns,
IsUnknownGatewayDeviceGateway,
Expand Down Expand Up @@ -1042,6 +1045,26 @@ export function isPortalSyncCode(syncCode: IsPortalSyncCodeSyncCode): syncCode i
return textSyncCode.test(syncCode);
}

/**
* Is session clean state.
*
* @param {IsSessionCleanStateOrbSecurityButtons} orbSecurityButtons - Orb security buttons.
*
* @returns {IsSessionCleanStateReturns}
*
* @since 1.0.0
*/
export function isSessionCleanState(orbSecurityButtons: IsSessionCleanStateOrbSecurityButtons): IsSessionCleanStateReturns {
// When at least 1 security button is disabled, it means the system is busy changing state.
if (orbSecurityButtons.some((orbSecurityButton) => orbSecurityButton.buttonDisabled)) {
return false;
}

return orbSecurityButtons
.filter((orbSecurityButton): orbSecurityButton is IsSessionCleanStateReadyButton => !orbSecurityButton.buttonDisabled)
.every((orbSecurityButton) => !['disarmed', 'disarmed+with+alarm', 'night+stay'].includes(orbSecurityButton.urlParams.armState));
}

/**
* Is unknown do submit handler collection.
*
Expand Down
13 changes: 11 additions & 2 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1080,8 +1080,6 @@ export type ADTPulseTestStartTestReturns = Promise<void>;
/**
* ADT Pulse Test - Zod parse response.
*
* @private
*
* @since 1.0.0
*/
export type ADTPulseTestZodParseResponse = z.SafeParseReturnType<any, any> | undefined;
Expand Down Expand Up @@ -1716,6 +1714,17 @@ export type IsPortalSyncCodeSyncCode = string;

export type IsPortalSyncCodeTypeGuard = PortalSyncCode;

/**
* Is session clean state.
*
* @since 1.0.0
*/
export type IsSessionCleanStateOrbSecurityButtons = OrbSecurityButtons;

export type IsSessionCleanStateReturns = boolean;

export type IsSessionCleanStateReadyButton = OrbSecurityButtonBase & OrbSecurityButtonReady;

/**
* Is unknown do submit handler collection.
*
Expand Down

0 comments on commit db078cc

Please sign in to comment.