Skip to content

Commit

Permalink
fix: only pass Z-Wave LR protocol flag to SmartStart inclusion
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Jan 16, 2024
1 parent f0d0dde commit 2e7971d
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 82 deletions.
10 changes: 5 additions & 5 deletions packages/zwave-js/src/Utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
export {
ProtocolDataRate,
ProtocolType,
ProtocolVersion,
Protocols,
QRCodeVersion,
RouteProtocolDataRate,
extractFirmware,
guessFirmwareFileFormat,
parseQRCodeString,
Expand All @@ -8,12 +13,7 @@ export {
export type {
Firmware,
FirmwareFileFormat,
ProtocolDataRate,
ProtocolType,
ProtocolVersion,
Protocols,
QRProvisioningInformation,
RouteProtocolDataRate,
protocolDataRateToString,
} from "@zwave-js/core";
export {
Expand Down
87 changes: 34 additions & 53 deletions packages/zwave-js/src/lib/controller/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ import {
type ExclusionOptions,
ExclusionStrategy,
type FoundNode,
type InclusionFlagsInternal,
type InclusionOptions,
type InclusionOptionsInternal,
type InclusionResult,
Expand Down Expand Up @@ -1298,19 +1297,20 @@ export class ZWaveController
// fetch the list of long range nodes until the controller reports no more
const lrNodeIds = await this.getLongRangeNodes();
let lrChannel: LongRangeChannel | undefined;
let maxPayloadSize : number | undefined;
let maxPayloadSize: number | undefined;
if (
this.isSerialAPISetupCommandSupported(
SerialAPISetupCommand.GetMaximumPayloadSize
SerialAPISetupCommand.GetMaximumPayloadSize,
)
) {
maxPayloadSize = await this.getMaxPayloadSize();
maxPayloadSize = await this.getMaxPayloadSize();
}
let maxPayloadSizeLR: number | undefined;
if (this.isLongRange() && this.isSerialAPISetupCommandSupported(
SerialAPISetupCommand.GetLongRangeMaximumPayloadSize
)
) {
if (
this.isLongRange() && this.isSerialAPISetupCommandSupported(
SerialAPISetupCommand.GetLongRangeMaximumPayloadSize,
)
) {
// TODO: restore/set the channel
const lrChannelResp = await this.driver.sendMessage<
GetLongRangeChannelResponse
Expand Down Expand Up @@ -1617,7 +1617,6 @@ export class ZWaveController
private _includeController: boolean = false;
private _exclusionOptions: ExclusionOptions | undefined;
private _inclusionOptions: InclusionOptionsInternal | undefined;
private _inclusionFlags: InclusionFlagsInternal | undefined;
private _nodePendingInclusion: ZWaveNode | undefined;
private _nodePendingExclusion: ZWaveNode | undefined;
private _nodePendingReplace: ZWaveNode | undefined;
Expand Down Expand Up @@ -1655,25 +1654,11 @@ export class ZWaveController
);
}

// BUGBUG: fix me
// if (options.isLongRange && !this.isLongRange()) {
// throw new ZWaveError(
// `Invalid long range inclusion on a non-LR host`,
// ZWaveErrorCodes.Argument_Invalid,
// )
// }
const isLongRange = this.isLongRange();

// Leave SmartStart listening mode so we can switch to exclusion mode
await this.pauseSmartStart();

this.setInclusionState(InclusionState.Including);
this._inclusionOptions = options;
this._inclusionFlags = {
highPower: true,
networkWide: true,
protocolLongRange: isLongRange,
};

try {
this.driver.controllerLog.print(
Expand All @@ -1689,7 +1674,8 @@ export class ZWaveController
await this.driver.sendMessage(
new AddNodeToNetworkRequest(this.driver, {
addNodeType: AddNodeType.Any,
...this._inclusionFlags,
highPower: true,
networkWide: true,
}),
);

Expand Down Expand Up @@ -1744,11 +1730,6 @@ export class ZWaveController
strategy: InclusionStrategy.SmartStart,
provisioning: provisioningEntry,
};
this._inclusionFlags = {
highPower: true,
networkWide: true,
protocolLongRange: provisioningEntry.isLongRange,
};

try {
this.driver.controllerLog.print(
Expand All @@ -1761,7 +1742,9 @@ export class ZWaveController
new AddNodeDSKToNetworkRequest(this.driver, {
nwiHomeId: nwiHomeIdFromDSK(dskBuffer),
authHomeId: authHomeIdFromDSK(dskBuffer),
...this._inclusionFlags,
protocol: provisioningEntry.protocol,
highPower: true,
networkWide: true,
}),
);

Expand Down Expand Up @@ -1789,7 +1772,8 @@ export class ZWaveController
new AddNodeToNetworkRequest(this.driver, {
callbackId: 0, // disable callbacks
addNodeType: AddNodeType.Stop,
...this._inclusionFlags,
highPower: true,
networkWide: true,
}),
);
this.driver.controllerLog.print(`The inclusion process was stopped`);
Expand All @@ -1808,7 +1792,8 @@ export class ZWaveController
>(
new AddNodeToNetworkRequest(this.driver, {
addNodeType: AddNodeType.Stop,
...this._inclusionFlags,
highPower: true,
networkWide: true,
}),
);
if (response.status === AddNodeStatus.Done) {
Expand Down Expand Up @@ -1841,7 +1826,8 @@ export class ZWaveController
await this.driver.sendMessage(
new AddNodeToNetworkRequest(this.driver, {
addNodeType: AddNodeType.Stop,
...this._inclusionFlags,
highPower: true,
networkWide: true,
}),
);
this.driver.controllerLog.print(
Expand Down Expand Up @@ -1939,7 +1925,8 @@ export class ZWaveController
new AddNodeToNetworkRequest(this.driver, {
callbackId: 0, // disable callbacks
addNodeType: AddNodeType.Stop,
...this._inclusionFlags,
highPower: true,
networkWide: true,
}),
);
this.driver.controllerLog.print(
Expand Down Expand Up @@ -1980,7 +1967,8 @@ export class ZWaveController
new AddNodeToNetworkRequest(this.driver, {
callbackId: 0, // disable callbacks
addNodeType: AddNodeType.Stop,
...this._inclusionFlags,
highPower: true,
networkWide: true,
}),
);
this.driver.controllerLog.print(
Expand Down Expand Up @@ -2022,32 +2010,19 @@ export class ZWaveController
return false;
}

// BUGBUG: fix me, same logic as beginInclusion, probably an incoming option...
// if (options.isLongRange && !this.isLongRange()) {
// throw new ZWaveError(
// `Invalid long range inclusion on a non-LR host`,
// ZWaveErrorCodes.Argument_Invalid,
// )
// }
const isLongRange = this.isLongRange();

// Leave SmartStart listening mode so we can switch to exclusion mode
await this.pauseSmartStart();

this.setInclusionState(InclusionState.Excluding);
this.driver.controllerLog.print(`starting exclusion process...`);
this._inclusionFlags = {
highPower: true,
networkWide: true,
protocolLongRange: isLongRange,
};

try {
// kick off the inclusion process
await this.driver.sendMessage(
new RemoveNodeFromNetworkRequest(this.driver, {
removeNodeType: RemoveNodeType.Any,
...this._inclusionFlags,
highPower: true,
networkWide: true,
}),
);
this.driver.controllerLog.print(
Expand Down Expand Up @@ -2084,7 +2059,8 @@ export class ZWaveController
new RemoveNodeFromNetworkRequest(this.driver, {
callbackId: 0, // disable callbacks
removeNodeType: RemoveNodeType.Stop,
...this._inclusionFlags,
highPower: true,
networkWide: true,
}),
);
this.driver.controllerLog.print(`the exclusion process was stopped`);
Expand All @@ -2107,7 +2083,8 @@ export class ZWaveController
await this.driver.sendMessage(
new RemoveNodeFromNetworkRequest(this.driver, {
removeNodeType: RemoveNodeType.Stop,
...this._inclusionFlags,
highPower: true,
networkWide: true,
}),
);
this.driver.controllerLog.print(
Expand Down Expand Up @@ -5895,7 +5872,11 @@ ${associatedNodes.join(", ")}`,
const result = await this.driver.sendMessage<
| SerialAPISetup_GetLongRangeMaximumPayloadSizeResponse
| SerialAPISetup_CommandUnsupportedResponse
>(new SerialAPISetup_GetLongRangeMaximumPayloadSizeRequest(this.driver));
>(
new SerialAPISetup_GetLongRangeMaximumPayloadSizeRequest(
this.driver,
),
);
if (result instanceof SerialAPISetup_CommandUnsupportedResponse) {
throw new ZWaveError(
`Your hardware does not support getting the max. long range payload size!`,
Expand Down
18 changes: 7 additions & 11 deletions packages/zwave-js/src/lib/controller/Inclusion.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { CommandClasses, SecurityClass } from "@zwave-js/core/safe";
import type {
CommandClasses,
Protocols,
SecurityClass,
} from "@zwave-js/core/safe";
import type { DeviceClass } from "../node/DeviceClass";

/** Additional information about the outcome of a node inclusion */
Expand Down Expand Up @@ -182,13 +186,6 @@ export type InclusionOptionsInternal =
provisioning: PlannedProvisioningEntry;
};

// BUGBUG: better way to do this?
export type InclusionFlagsInternal = {
highPower: boolean;
networkWide: boolean;
protocolLongRange: boolean;
};

export type ExclusionOptions = {
strategy:
| ExclusionStrategy.ExcludeOnly
Expand Down Expand Up @@ -237,9 +234,8 @@ export interface PlannedProvisioningEntry {
/** The device specific key (DSK) in the form aaaaa-bbbbb-ccccc-ddddd-eeeee-fffff-11111-22222 */
dsk: string;

/** The device must be included via ZWave Long Range */
// BUGBUG: by adding this here we probably broke the API used by JSUI, etc...
isLongRange: boolean;
/** Which protocol to use for inclusion. Default: Z-Wave Classic */
protocol?: Protocols;

/** The security classes that have been **granted** by the user */
securityClasses: SecurityClass[];
Expand Down
11 changes: 11 additions & 0 deletions packages/zwave-js/src/lib/driver/NetworkCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { JsonlDB } from "@alcalzone/jsonl-db";
import {
type CommandClasses,
NodeType,
Protocols,
SecurityClass,
ZWaveError,
ZWaveErrorCodes,
Expand Down Expand Up @@ -203,6 +204,10 @@ function tryParseProvisioningList(
entry.status as any
] as any as ProvisioningEntryStatus;
}
if (entry.protocol != undefined) {
parsed.protocol =
Protocols[entry.protocol as any] as any as Protocols;
}
ret.push(parsed);
} else {
return;
Expand Down Expand Up @@ -452,6 +457,12 @@ export function serializeNetworkCacheValue(
entry.status,
);
}
if (entry.protocol != undefined) {
serialized.protocol = getEnumMemberName(
Protocols,
entry.protocol,
);
}
ret.push(serialized);
}
return ret;
Expand Down
Loading

0 comments on commit 2e7971d

Please sign in to comment.