Skip to content

Commit

Permalink
Minor improvements
Browse files Browse the repository at this point in the history
### UPDATED
- Detection improvements towards `fetchTableCells()` to not include incremented nodes that have empty strings and to not include nodes that have 0 length.
- Better detection for gateway names.

v3.0.2
  • Loading branch information
mrjackyliang committed Jan 18, 2024
1 parent 5b6d5bb commit d9bb7e5
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 30 deletions.
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.0.1",
"version": "3.0.2",
"description": "Homebridge security system platform for ADT Pulse",
"main": "./build/src/index.js",
"exports": "./build/src/index.js",
Expand Down
16 changes: 11 additions & 5 deletions src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -867,14 +867,17 @@ export class ADTPulse {
await this.newInformationDispatcher('gateway-information', gatewayInformation);

// If the parsing function may be parsing data incorrectly.
if (Object.keys(fetchedTableCells).length !== 18) {
if (
Object.keys(fetchedTableCells).length !== 11 // Compact SMA Protocol Gateway / Cellular Mode.
&& Object.keys(fetchedTableCells).length !== 18 // ADT Pulse Gateway / Broadband Mode.
) {
if (this.#internal.debug) {
debugLog(this.#internal.logger, 'api.ts / ADTPulse.getGatewayInformation()', 'warn', 'The fetchTableCells() function may be parsing the gateway information incorrectly');
}

await this.newInformationDispatcher('debug-parser', {
parserName: 'fetchTableCells()',
parserReason: 'length does not equal to 18',
parserReason: 'length does not match 11 or 18',
parserResponse: fetchedTableCells,
rawData: sessions.axiosSystemGateway.data,
});
Expand Down Expand Up @@ -1079,14 +1082,17 @@ export class ADTPulse {
await this.newInformationDispatcher('panel-information', panelInformation);

// If the parsing function may be parsing data incorrectly.
if (Object.keys(fetchedTableCells).length !== 5) {
if (
Object.keys(fetchedTableCells).length !== 4 // Impassa SCW9057.
&& Object.keys(fetchedTableCells).length !== 5 // Safewatch Pro 3000/3000CN.
) {
if (this.#internal.debug) {
debugLog(this.#internal.logger, 'api.ts / ADTPulse.getPanelInformation()', 'warn', 'The fetchTableCells() function may be parsing the panel information incorrectly');
}

await this.newInformationDispatcher('debug-parser', {
parserName: 'fetchTableCells()',
parserReason: 'length does not equal to 5',
parserReason: 'length does not match 4 or 5',
parserResponse: fetchedTableCells,
rawData: sessions.axiosSystemDeviceId1.data,
});
Expand Down Expand Up @@ -3157,7 +3163,7 @@ export class ADTPulse {

await this.newInformationDispatcher('debug-parser', {
parserName: 'parseDoSubmitHandlers()',
parserReason: 'length does not equal to 2',
parserReason: 'length does not match 2',
parserResponse: parsedDoSubmitHandlers,
rawData: response.data,
});
Expand Down
41 changes: 21 additions & 20 deletions src/lib/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ export class ADTPulsePlatform implements ADTPulsePlatformPlugin {
* @since 1.0.0
*/
private async logStatusChanges(oldCache: ADTPulsePlatformLogStatusChangesOldCache, newCache: ADTPulsePlatformLogStatusChangesNewCache): ADTPulsePlatformLogStatusChangesReturns {
// Fetch gateway device status.
// Fetch gateway information.
if (oldCache.gatewayInfo !== null && newCache.gatewayInfo !== null) {
const oldStatus = oldCache.gatewayInfo.status;
const newStatus = newCache.gatewayInfo.status;
Expand All @@ -896,7 +896,7 @@ export class ADTPulsePlatform implements ADTPulsePlatformPlugin {
}
}

// Fetch the panel device status.
// Fetch the panel information.
if (oldCache.panelInfo !== null && newCache.panelInfo !== null) {
const oldStatus = oldCache.panelInfo.status;
const newStatus = newCache.panelInfo.status;
Expand All @@ -906,7 +906,19 @@ export class ADTPulsePlatform implements ADTPulsePlatformPlugin {
}
}

// Fetch the sensors device status.
// Fetch the panel status.
if (oldCache.panelStatus !== null && newCache.panelStatus !== null) {
const oldStatus = oldCache.panelStatus.rawData.node;
const newStatus = newCache.panelStatus.rawData.node;
const splitOldStatus = oldStatus.split(textOrbTextSummarySections).filter(Boolean).join(' / ');
const splitNewStatus = newStatus.split(textOrbTextSummarySections).filter(Boolean).join(' / ');

if (oldStatus !== newStatus) {
this.#log.info(`${chalk.underline('Security Panel')} state changed (old: "${splitOldStatus}", new: "${splitNewStatus}").`);
}
}

// Fetch the sensors information.
if (
this.#config !== null
&& this.#config.sensors.length > 0 // Only show status changed if user configured sensors.
Expand All @@ -925,27 +937,15 @@ export class ADTPulsePlatform implements ADTPulsePlatformPlugin {
}
}
} else {
this.#log.warn('Changes to sensors device status cannot be determined due to length inconsistencies.');
this.#log.warn('Changes to sensors information cannot be determined due to length inconsistencies.');
stackTracer('log-status-changes', {
old: oldCache.sensorsInfo,
new: newCache.sensorsInfo,
});
}
}

// Fetch the panel device state.
if (oldCache.panelStatus !== null && newCache.panelStatus !== null) {
const oldStatus = oldCache.panelStatus.rawData.node;
const newStatus = newCache.panelStatus.rawData.node;
const splitOldStatus = oldStatus.split(textOrbTextSummarySections).filter(Boolean).join(' / ');
const splitNewStatus = newStatus.split(textOrbTextSummarySections).filter(Boolean).join(' / ');

if (oldStatus !== newStatus) {
this.#log.info(`${chalk.underline('Security Panel')} state changed (old: "${splitOldStatus}", new: "${splitNewStatus}").`);
}
}

// Fetch the sensors device state.
// Fetch the sensors status.
if (
this.#config !== null
&& this.#config.sensors.length > 0 // Only show status changed if user configured sensors.
Expand All @@ -964,7 +964,7 @@ export class ADTPulsePlatform implements ADTPulsePlatformPlugin {
}
}
} else {
this.#log.warn('Changes to sensors device state cannot be determined due to length inconsistencies.');
this.#log.warn('Changes to sensors status cannot be determined due to length inconsistencies.');
stackTracer('log-status-changes', {
old: oldCache.sensorsStatus,
new: newCache.sensorsStatus,
Expand Down Expand Up @@ -1044,11 +1044,12 @@ export class ADTPulsePlatform implements ADTPulsePlatformPlugin {
// Add gateway as an accessory.
if (gatewayInfo !== null) {
const id = 'adt-device-0';
const name = gatewayInfo.manufacturer ?? gatewayInfo.model ?? 'ADT Pulse Gateway';

devices.push({
id,
name: 'ADT Pulse Gateway',
originalName: 'ADT Pulse Gateway',
name: (name.includes('Gateway')) ? name : 'ADT Pulse Gateway',
originalName: (name.includes('Gateway')) ? name : 'ADT Pulse Gateway',
type: 'gateway',
zone: null,
category: 'OTHER',
Expand Down
15 changes: 11 additions & 4 deletions src/lib/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,13 @@ export function fetchTableCells(nodeElements: FetchTableCellsNodeElements, match
* - nodes[51].textContent = "12345"
* - nodes[52].textContent = "67890"
* - nodes[53].textContent = null
* - nodes[54].textContent = "abcdef"
* - nodes[54].textContent = ""
* - nodes[55].textContent = "abcdef"
*
* If your criteria is set to the following settings, the result would be:
* (match: "Example", incrementFrom: 0, incrementTo: 1) ➜ { "Example": ["Example", "12345"] }
* (match: "Example", incrementFrom: 1, incrementTo: 3) ➜ { "Example": ["12345", "67890"] }
* (match: "Example", incrementFrom: 0, incrementTo: 4) ➜ { "Example": ["Example", "12345", "67890", "abcdef"] }
* (match: "Example", incrementFrom: 0, incrementTo: 5) ➜ { "Example": ["Example", "12345", "67890", "abcdef"] }
*
* @since 1.0.0
*/
Expand All @@ -491,11 +492,17 @@ export function fetchTableCells(nodeElements: FetchTableCellsNodeElements, match
if (incrementedNode !== null) {
const incrementedNodeCleaned = clearWhitespace(incrementedNode);

collectedNodes.push(incrementedNodeCleaned);
// If content of "incrementedNode" is not empty.
if (incrementedNodeCleaned !== '') {
collectedNodes.push(incrementedNodeCleaned);
}
}
}

matched[currentNodeCleaned] = collectedNodes;
// If the current node is not empty.
if (collectedNodes.length > 0) {
matched[currentNodeCleaned] = collectedNodes;
}
});

return matched;
Expand Down

0 comments on commit d9bb7e5

Please sign in to comment.