Skip to content

Commit

Permalink
refactor: split up ZWaveApplicationHost even more
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Oct 16, 2024
1 parent 4c342cd commit dc7e12d
Show file tree
Hide file tree
Showing 59 changed files with 463 additions and 402 deletions.
14 changes: 7 additions & 7 deletions packages/cc/src/cc/AlarmSensorCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class AlarmSensorCC extends CommandClass {

// Skip the interview in favor of Notification CC if possible
if (endpoint.supportsCC(CommandClasses.Notification)) {
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message:
`${this.constructor.name}: skipping interview because Notification CC is supported...`,
Expand All @@ -195,14 +195,14 @@ export class AlarmSensorCC extends CommandClass {
priority: MessagePriority.NodeQuery,
});

applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: `Interviewing ${this.ccName}...`,
direction: "none",
});

// Find out which sensor types this sensor supports
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: "querying supported sensor types...",
direction: "outbound",
Expand All @@ -215,13 +215,13 @@ export class AlarmSensorCC extends CommandClass {
.map((name) => `\n· ${name}`)
.join("")
}`;
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: logMessage,
direction: "inbound",
});
} else {
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message:
"Querying supported sensor types timed out, skipping interview...",
Expand Down Expand Up @@ -262,7 +262,7 @@ export class AlarmSensorCC extends CommandClass {

const sensorName = getEnumMemberName(AlarmSensorType, type);

applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: `querying current value for ${sensorName}...`,
direction: "outbound",
Expand All @@ -279,7 +279,7 @@ severity: ${currentValue.severity}`;
message += `
duration: ${currentValue.duration}`;
}
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message,
direction: "inbound",
Expand Down
14 changes: 7 additions & 7 deletions packages/cc/src/cc/AssociationCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ export class AssociationCC extends CommandClass {
priority: MessagePriority.NodeQuery,
});

applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: `Interviewing ${this.ccName}...`,
direction: "none",
Expand All @@ -412,20 +412,20 @@ export class AssociationCC extends CommandClass {
// multi channel association groups

// Find out how many groups are supported
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: "querying number of association groups...",
direction: "outbound",
});
const groupCount = await api.getGroupCount();
if (groupCount != undefined) {
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: `supports ${groupCount} association groups`,
direction: "inbound",
});
} else {
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message:
"Querying association groups timed out, skipping interview...",
Expand All @@ -439,7 +439,7 @@ export class AssociationCC extends CommandClass {

// Skip the remaining Association CC interview in favor of Multi Channel Association if possible
if (endpoint.supportsCC(CommandClasses["Multi Channel Association"])) {
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message:
`${this.constructor.name}: delaying configuration of lifeline associations until after Multi Channel Association interview...`,
Expand Down Expand Up @@ -476,7 +476,7 @@ export class AssociationCC extends CommandClass {

// Query each association group
for (let groupId = 1; groupId <= groupCount; groupId++) {
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: `querying association group #${groupId}...`,
direction: "outbound",
Expand All @@ -487,7 +487,7 @@ export class AssociationCC extends CommandClass {
`received information for association group #${groupId}:
maximum # of nodes: ${group.maxNodes}
currently assigned nodes: ${group.nodeIds.map(String).join(", ")}`;
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: logMessage,
direction: "inbound",
Expand Down
12 changes: 6 additions & 6 deletions packages/cc/src/cc/AssociationGroupInfoCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ export class AssociationGroupInfoCC extends CommandClass {
endpoint,
).withOptions({ priority: MessagePriority.NodeQuery });

applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: `Interviewing ${this.ccName}...`,
direction: "none",
Expand All @@ -378,7 +378,7 @@ export class AssociationGroupInfoCC extends CommandClass {

for (let groupId = 1; groupId <= associationGroupCount; groupId++) {
// First get the group's name
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: `Association group #${groupId}: Querying name...`,
direction: "outbound",
Expand All @@ -387,15 +387,15 @@ export class AssociationGroupInfoCC extends CommandClass {
if (name) {
const logMessage =
`Association group #${groupId} has name "${name}"`;
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: logMessage,
direction: "inbound",
});
}

// Then the command list
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message:
`Association group #${groupId}: Querying command list...`,
Expand Down Expand Up @@ -436,7 +436,7 @@ export class AssociationGroupInfoCC extends CommandClass {

for (let groupId = 1; groupId <= associationGroupCount; groupId++) {
// Then its information
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: `Association group #${groupId}: Querying info...`,
direction: "outbound",
Expand All @@ -452,7 +452,7 @@ profile: ${
info.profile,
)
}`;
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: logMessage,
direction: "inbound",
Expand Down
14 changes: 7 additions & 7 deletions packages/cc/src/cc/BarrierOperatorCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ export class BarrierOperatorCC extends CommandClass {
priority: MessagePriority.NodeQuery,
});

applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: `Interviewing ${this.ccName}...`,
direction: "none",
Expand All @@ -442,13 +442,13 @@ export class BarrierOperatorCC extends CommandClass {
// Create targetState value if it does not exist
this.ensureMetadata(applHost, BarrierOperatorCCValues.targetState);

applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
message: "Querying signaling capabilities...",
direction: "outbound",
});
const resp = await api.getSignalingCapabilities();
if (resp) {
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
message: `Received supported subsystem types: ${
resp
.map((t) =>
Expand All @@ -465,7 +465,7 @@ export class BarrierOperatorCC extends CommandClass {
// for valid values and throws otherwise.
if (!isEnumMember(SubsystemType, subsystemType)) continue;

applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
message: `Enabling subsystem ${
getEnumMemberName(
SubsystemType,
Expand Down Expand Up @@ -508,7 +508,7 @@ export class BarrierOperatorCC extends CommandClass {
// for valid values and throws otherwise.
if (!isEnumMember(SubsystemType, subsystemType)) continue;

applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
message: `Querying event signaling state for subsystem ${
getEnumMemberName(
SubsystemType,
Expand All @@ -519,7 +519,7 @@ export class BarrierOperatorCC extends CommandClass {
});
const state = await api.getEventSignaling(subsystemType);
if (state != undefined) {
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
message: `Subsystem ${
getEnumMemberName(
SubsystemType,
Expand All @@ -531,7 +531,7 @@ export class BarrierOperatorCC extends CommandClass {
}
}

applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
message: "querying current barrier state...",
direction: "outbound",
});
Expand Down
8 changes: 4 additions & 4 deletions packages/cc/src/cc/BasicCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export class BasicCC extends CommandClass {
const node = this.getNode(applHost)!;
const endpoint = this.getEndpoint(applHost)!;

applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: `Interviewing ${this.ccName}...`,
direction: "none",
Expand All @@ -275,7 +275,7 @@ export class BasicCC extends CommandClass {
if (
this.getValue(applHost, BasicCCValues.currentValue) == undefined
) {
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message:
"No response to Basic Get command, assuming Basic CC is unsupported...",
Expand Down Expand Up @@ -306,7 +306,7 @@ export class BasicCC extends CommandClass {
});

// try to query the current state
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: "querying Basic CC state...",
direction: "outbound",
Expand All @@ -321,7 +321,7 @@ current value: ${basicResponse.currentValue}`;
target value: ${basicResponse.targetValue}
remaining duration: ${basicResponse.duration?.toString() ?? "undefined"}`;
}
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: logMessage,
direction: "inbound",
Expand Down
10 changes: 5 additions & 5 deletions packages/cc/src/cc/BatteryCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export class BatteryCC extends CommandClass {
): Promise<void> {
const node = this.getNode(applHost)!;

applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: `Interviewing ${this.ccName}...`,
direction: "none",
Expand All @@ -308,7 +308,7 @@ export class BatteryCC extends CommandClass {
priority: MessagePriority.NodeQuery,
});

applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: "querying battery status...",
direction: "outbound",
Expand All @@ -335,7 +335,7 @@ needs to be replaced or charged: ${
is low temperature ${batteryStatus.lowTemperatureStatus}
is disconnected: ${batteryStatus.disconnected}`;
}
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: logMessage,
direction: "inbound",
Expand All @@ -344,7 +344,7 @@ is disconnected: ${batteryStatus.disconnected}`;

if (api.version >= 2) {
// always query the health
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: "querying battery health...",
direction: "outbound",
Expand All @@ -355,7 +355,7 @@ is disconnected: ${batteryStatus.disconnected}`;
const logMessage = `received response for battery health:
max. capacity: ${batteryHealth.maximumCapacity} %
temperature: ${batteryHealth.temperature} °C`;
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: logMessage,
direction: "inbound",
Expand Down
16 changes: 8 additions & 8 deletions packages/cc/src/cc/BinarySensorCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,15 @@ export class BinarySensorCC extends CommandClass {
priority: MessagePriority.NodeQuery,
});

applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: `Interviewing ${this.ccName}...`,
direction: "none",
});

// Find out which sensor types this sensor supports
if (api.version >= 2) {
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: "querying supported sensor types...",
direction: "outbound",
Expand All @@ -226,13 +226,13 @@ export class BinarySensorCC extends CommandClass {
.map((name) => `\n· ${name}`)
.join("")
}`;
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: logMessage,
direction: "inbound",
});
} else {
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message:
"Querying supported sensor types timed out, skipping interview...",
Expand Down Expand Up @@ -263,14 +263,14 @@ export class BinarySensorCC extends CommandClass {

// Query (all of) the sensor's current value(s)
if (api.version === 1) {
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: "querying current value...",
direction: "outbound",
});
const currentValue = await api.get();
if (currentValue != undefined) {
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: `received current value: ${currentValue}`,
direction: "inbound",
Expand All @@ -289,14 +289,14 @@ export class BinarySensorCC extends CommandClass {
if (!isEnumMember(BinarySensorType, type)) continue;

const sensorName = getEnumMemberName(BinarySensorType, type);
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message: `querying current value for ${sensorName}...`,
direction: "outbound",
});
const currentValue = await api.get(type);
if (currentValue != undefined) {
applHost.controllerLog.logNode(node.id, {
applHost.logNode(node.id, {
endpoint: this.endpointIndex,
message:
`received current value for ${sensorName}: ${currentValue}`,
Expand Down
Loading

0 comments on commit dc7e12d

Please sign in to comment.