Skip to content

Commit d9bb7e5

Browse files
committed
Minor improvements
### 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
1 parent 5b6d5bb commit d9bb7e5

File tree

4 files changed

+44
-30
lines changed

4 files changed

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

src/lib/api.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -867,14 +867,17 @@ export class ADTPulse {
867867
await this.newInformationDispatcher('gateway-information', gatewayInformation);
868868

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

875878
await this.newInformationDispatcher('debug-parser', {
876879
parserName: 'fetchTableCells()',
877-
parserReason: 'length does not equal to 18',
880+
parserReason: 'length does not match 11 or 18',
878881
parserResponse: fetchedTableCells,
879882
rawData: sessions.axiosSystemGateway.data,
880883
});
@@ -1079,14 +1082,17 @@ export class ADTPulse {
10791082
await this.newInformationDispatcher('panel-information', panelInformation);
10801083

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

10871093
await this.newInformationDispatcher('debug-parser', {
10881094
parserName: 'fetchTableCells()',
1089-
parserReason: 'length does not equal to 5',
1095+
parserReason: 'length does not match 4 or 5',
10901096
parserResponse: fetchedTableCells,
10911097
rawData: sessions.axiosSystemDeviceId1.data,
10921098
});
@@ -3157,7 +3163,7 @@ export class ADTPulse {
31573163

31583164
await this.newInformationDispatcher('debug-parser', {
31593165
parserName: 'parseDoSubmitHandlers()',
3160-
parserReason: 'length does not equal to 2',
3166+
parserReason: 'length does not match 2',
31613167
parserResponse: parsedDoSubmitHandlers,
31623168
rawData: response.data,
31633169
});

src/lib/platform.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ export class ADTPulsePlatform implements ADTPulsePlatformPlugin {
886886
* @since 1.0.0
887887
*/
888888
private async logStatusChanges(oldCache: ADTPulsePlatformLogStatusChangesOldCache, newCache: ADTPulsePlatformLogStatusChangesNewCache): ADTPulsePlatformLogStatusChangesReturns {
889-
// Fetch gateway device status.
889+
// Fetch gateway information.
890890
if (oldCache.gatewayInfo !== null && newCache.gatewayInfo !== null) {
891891
const oldStatus = oldCache.gatewayInfo.status;
892892
const newStatus = newCache.gatewayInfo.status;
@@ -896,7 +896,7 @@ export class ADTPulsePlatform implements ADTPulsePlatformPlugin {
896896
}
897897
}
898898

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

909-
// Fetch the sensors device status.
909+
// Fetch the panel status.
910+
if (oldCache.panelStatus !== null && newCache.panelStatus !== null) {
911+
const oldStatus = oldCache.panelStatus.rawData.node;
912+
const newStatus = newCache.panelStatus.rawData.node;
913+
const splitOldStatus = oldStatus.split(textOrbTextSummarySections).filter(Boolean).join(' / ');
914+
const splitNewStatus = newStatus.split(textOrbTextSummarySections).filter(Boolean).join(' / ');
915+
916+
if (oldStatus !== newStatus) {
917+
this.#log.info(`${chalk.underline('Security Panel')} state changed (old: "${splitOldStatus}", new: "${splitNewStatus}").`);
918+
}
919+
}
920+
921+
// Fetch the sensors information.
910922
if (
911923
this.#config !== null
912924
&& this.#config.sensors.length > 0 // Only show status changed if user configured sensors.
@@ -925,27 +937,15 @@ export class ADTPulsePlatform implements ADTPulsePlatformPlugin {
925937
}
926938
}
927939
} else {
928-
this.#log.warn('Changes to sensors device status cannot be determined due to length inconsistencies.');
940+
this.#log.warn('Changes to sensors information cannot be determined due to length inconsistencies.');
929941
stackTracer('log-status-changes', {
930942
old: oldCache.sensorsInfo,
931943
new: newCache.sensorsInfo,
932944
});
933945
}
934946
}
935947

936-
// Fetch the panel device state.
937-
if (oldCache.panelStatus !== null && newCache.panelStatus !== null) {
938-
const oldStatus = oldCache.panelStatus.rawData.node;
939-
const newStatus = newCache.panelStatus.rawData.node;
940-
const splitOldStatus = oldStatus.split(textOrbTextSummarySections).filter(Boolean).join(' / ');
941-
const splitNewStatus = newStatus.split(textOrbTextSummarySections).filter(Boolean).join(' / ');
942-
943-
if (oldStatus !== newStatus) {
944-
this.#log.info(`${chalk.underline('Security Panel')} state changed (old: "${splitOldStatus}", new: "${splitNewStatus}").`);
945-
}
946-
}
947-
948-
// Fetch the sensors device state.
948+
// Fetch the sensors status.
949949
if (
950950
this.#config !== null
951951
&& this.#config.sensors.length > 0 // Only show status changed if user configured sensors.
@@ -964,7 +964,7 @@ export class ADTPulsePlatform implements ADTPulsePlatformPlugin {
964964
}
965965
}
966966
} else {
967-
this.#log.warn('Changes to sensors device state cannot be determined due to length inconsistencies.');
967+
this.#log.warn('Changes to sensors status cannot be determined due to length inconsistencies.');
968968
stackTracer('log-status-changes', {
969969
old: oldCache.sensorsStatus,
970970
new: newCache.sensorsStatus,
@@ -1044,11 +1044,12 @@ export class ADTPulsePlatform implements ADTPulsePlatformPlugin {
10441044
// Add gateway as an accessory.
10451045
if (gatewayInfo !== null) {
10461046
const id = 'adt-device-0';
1047+
const name = gatewayInfo.manufacturer ?? gatewayInfo.model ?? 'ADT Pulse Gateway';
10471048

10481049
devices.push({
10491050
id,
1050-
name: 'ADT Pulse Gateway',
1051-
originalName: 'ADT Pulse Gateway',
1051+
name: (name.includes('Gateway')) ? name : 'ADT Pulse Gateway',
1052+
originalName: (name.includes('Gateway')) ? name : 'ADT Pulse Gateway',
10521053
type: 'gateway',
10531054
zone: null,
10541055
category: 'OTHER',

src/lib/utility.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,13 @@ export function fetchTableCells(nodeElements: FetchTableCellsNodeElements, match
475475
* - nodes[51].textContent = "12345"
476476
* - nodes[52].textContent = "67890"
477477
* - nodes[53].textContent = null
478-
* - nodes[54].textContent = "abcdef"
478+
* - nodes[54].textContent = ""
479+
* - nodes[55].textContent = "abcdef"
479480
*
480481
* If your criteria is set to the following settings, the result would be:
481482
* (match: "Example", incrementFrom: 0, incrementTo: 1) ➜ { "Example": ["Example", "12345"] }
482483
* (match: "Example", incrementFrom: 1, incrementTo: 3) ➜ { "Example": ["12345", "67890"] }
483-
* (match: "Example", incrementFrom: 0, incrementTo: 4) ➜ { "Example": ["Example", "12345", "67890", "abcdef"] }
484+
* (match: "Example", incrementFrom: 0, incrementTo: 5) ➜ { "Example": ["Example", "12345", "67890", "abcdef"] }
484485
*
485486
* @since 1.0.0
486487
*/
@@ -491,11 +492,17 @@ export function fetchTableCells(nodeElements: FetchTableCellsNodeElements, match
491492
if (incrementedNode !== null) {
492493
const incrementedNodeCleaned = clearWhitespace(incrementedNode);
493494

494-
collectedNodes.push(incrementedNodeCleaned);
495+
// If content of "incrementedNode" is not empty.
496+
if (incrementedNodeCleaned !== '') {
497+
collectedNodes.push(incrementedNodeCleaned);
498+
}
495499
}
496500
}
497501

498-
matched[currentNodeCleaned] = collectedNodes;
502+
// If the current node is not empty.
503+
if (collectedNodes.length > 0) {
504+
matched[currentNodeCleaned] = collectedNodes;
505+
}
499506
});
500507

501508
return matched;

0 commit comments

Comments
 (0)