Skip to content

Commit

Permalink
refactor: rename Controller (and related) members (#3761)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Feb 2, 2022
1 parent 984bf3f commit 9681323
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 59 deletions.
10 changes: 5 additions & 5 deletions docs/api/controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -640,13 +640,13 @@ readonly nodes: ReadonlyMap<number, ZWaveNode>

This property contains a map of all nodes that you can access by their node ID, e.g. `nodes.get(2)` for node 2.

### `libraryVersion`
### `sdkVersion`

```ts
readonly libraryVersion: string
readonly sdkVersion: string
```

Returns the Z-Wave library version that is supported by the controller hardware.
Returns the Z-Wave SDK version that is supported by the controller hardware.

> [!WARNING]
> This property is only defined after the controller interview!
Expand All @@ -657,7 +657,7 @@ Returns the Z-Wave library version that is supported by the controller hardware.
readonly type: ZWaveLibraryTypes
```

Returns the type of the Z-Wave library that is supported by the controller hardware. The following values are possible:
Returns the type of the Z-Wave library that is supported by the controller hardware. The following values are defined, although only `"Static Controller"` or `"Bridge Controller"` will realistically be possible:

<!-- #import ZWaveLibraryTypes from "zwave-js" -->

Expand Down Expand Up @@ -710,7 +710,7 @@ Returns the ID of the controller in the current network.
* readonly wasRealPrimary: boolean
* readonly isStaticUpdateController: boolean
* readonly isSlave: boolean
* readonly serialApiVersion: string
* readonly firmwareVersion: string
* readonly manufacturerId: number
* readonly productType: number
* readonly productId: number
Expand Down
78 changes: 37 additions & 41 deletions packages/zwave-js/src/lib/controller/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ import { ZWaveLibraryTypes } from "./ZWaveLibraryTypes";
import { protocolVersionToSDKVersion } from "./ZWaveSDKVersions";

export type HealNodeStatus = "pending" | "done" | "failed" | "skipped";
export type SerialAPIVersion =
export type SDKVersion =
| `${number}.${number}`
| `${number}.${number}.${number}`;

Expand Down Expand Up @@ -321,16 +321,16 @@ export class ZWaveController extends TypedEventEmitter<ControllerEventCallbacks>
);
}

private _libraryVersion: string | undefined;
public get libraryVersion(): string | undefined {
return this._libraryVersion;
}

private _type: ZWaveLibraryTypes | undefined;
public get type(): ZWaveLibraryTypes | undefined {
return this._type;
}

private _sdkVersion: string | undefined;
public get sdkVersion(): string | undefined {
return this._sdkVersion;
}

private _homeId: number | undefined;
/** A 32bit number identifying the current network */
public get homeId(): number | undefined {
Expand Down Expand Up @@ -373,48 +373,39 @@ export class ZWaveController extends TypedEventEmitter<ControllerEventCallbacks>
return this._isSlave;
}

private _serialApiVersion: string | undefined;
public get serialApiVersion(): string | undefined {
return this._serialApiVersion;
}

/** Checks if the Serial API version is greater than the given one */
public serialApiGt(version: SerialAPIVersion): boolean | undefined {
// TODO: Rename these to sdkVersionGt(e) etc...
if (this._libraryVersion === undefined) {
/** Checks if the SDK version is greater than the given one */
public sdkVersionGt(version: SDKVersion): boolean | undefined {
if (this._sdkVersion === undefined) {
return undefined;
}
const sdkVersion = protocolVersionToSDKVersion(this._libraryVersion);
const sdkVersion = protocolVersionToSDKVersion(this._sdkVersion);
return semver.gt(padVersion(sdkVersion), padVersion(version));
}

/** Checks if the Serial API version is greater than or equal to the given one */
public serialApiGte(version: SerialAPIVersion): boolean | undefined {
// TODO: Rename these to sdkVersionGt(e) etc...
if (this._libraryVersion === undefined) {
/** Checks if the SDK version is greater than or equal to the given one */
public sdkVersionGte(version: SDKVersion): boolean | undefined {
if (this._sdkVersion === undefined) {
return undefined;
}
const sdkVersion = protocolVersionToSDKVersion(this._libraryVersion);
const sdkVersion = protocolVersionToSDKVersion(this._sdkVersion);
return semver.gte(padVersion(sdkVersion), padVersion(version));
}

/** Checks if the Serial API version is lower than the given one */
public serialApiLt(version: SerialAPIVersion): boolean | undefined {
// TODO: Rename these to sdkVersionGt(e) etc...
if (this._libraryVersion === undefined) {
/** Checks if the SDK version is lower than the given one */
public sdkVersionLt(version: SDKVersion): boolean | undefined {
if (this._sdkVersion === undefined) {
return undefined;
}
const sdkVersion = protocolVersionToSDKVersion(this._libraryVersion);
const sdkVersion = protocolVersionToSDKVersion(this._sdkVersion);
return semver.lt(padVersion(sdkVersion), padVersion(version));
}

/** Checks if the Serial API version is lower than or equal to the given one */
public serialApiLte(version: SerialAPIVersion): boolean | undefined {
// TODO: Rename these to sdkVersionGt(e) etc...
if (this._libraryVersion === undefined) {
/** Checks if the SDK version is lower than or equal to the given one */
public sdkVersionLte(version: SDKVersion): boolean | undefined {
if (this._sdkVersion === undefined) {
return undefined;
}
const sdkVersion = protocolVersionToSDKVersion(this._libraryVersion);
const sdkVersion = protocolVersionToSDKVersion(this._sdkVersion);
return semver.lte(padVersion(sdkVersion), padVersion(version));
}

Expand All @@ -433,6 +424,11 @@ export class ZWaveController extends TypedEventEmitter<ControllerEventCallbacks>
return this._productId;
}

private _firmwareVersion: string | undefined;
public get firmwareVersion(): string | undefined {
return this._firmwareVersion;
}

private _supportedFunctionTypes: FunctionType[] | undefined;
public get supportedFunctionTypes(): readonly FunctionType[] | undefined {
return this._supportedFunctionTypes;
Expand Down Expand Up @@ -478,7 +474,7 @@ export class ZWaveController extends TypedEventEmitter<ControllerEventCallbacks>
public supportsFeature(feature: ZWaveFeature): boolean | undefined {
switch (feature) {
case ZWaveFeature.SmartStart:
return this.serialApiGte(minFeatureVersions[feature]);
return this.sdkVersionGte(minFeatureVersions[feature]);
}
}

Expand Down Expand Up @@ -695,14 +691,14 @@ export class ZWaveController extends TypedEventEmitter<ControllerEventCallbacks>
supportCheck: false,
},
);
this._serialApiVersion = apiCaps.serialApiVersion;
this._firmwareVersion = apiCaps.firmwareVersion;
this._manufacturerId = apiCaps.manufacturerId;
this._productType = apiCaps.productType;
this._productId = apiCaps.productId;
this._supportedFunctionTypes = apiCaps.supportedFunctionTypes;
this.driver.controllerLog.print(
`received API capabilities:
serial API version: ${this._serialApiVersion}
firmware version: ${this._firmwareVersion}
manufacturer ID: ${num2hex(this._manufacturerId)}
product type: ${num2hex(this._productType)}
product ID: ${num2hex(this._productId)}
Expand All @@ -729,12 +725,12 @@ export class ZWaveController extends TypedEventEmitter<ControllerEventCallbacks>
supportCheck: false,
},
);
this._libraryVersion = version.libraryVersion;
this._sdkVersion = version.sdkVersion;
this._type = version.controllerType;
this.driver.controllerLog.print(
`received version info:
controller type: ${ZWaveLibraryTypes[this._type]}
library version: ${this._libraryVersion}`,
library version: ${this._sdkVersion}`,
);

this.driver.controllerLog.print(
Expand Down Expand Up @@ -948,7 +944,7 @@ export class ZWaveController extends TypedEventEmitter<ControllerEventCallbacks>
getFirmwareVersionsMetadata(),
);
controllerValueDB.setValue(getFirmwareVersionsValueId(), [
this._serialApiVersion,
this._firmwareVersion,
]);

if (
Expand Down Expand Up @@ -4536,7 +4532,7 @@ ${associatedNodes.join(", ")}`,

let ret: Buffer;
try {
if (this.serialApiGte("7.0")) {
if (this.sdkVersionGte("7.0")) {
ret = await this.backupNVMRaw700(onProgress);
} else {
ret = await this.backupNVMRaw500(onProgress);
Expand Down Expand Up @@ -4665,15 +4661,15 @@ ${associatedNodes.join(", ")}`,
"Converting NVM to target format...",
);
let targetNVM: Buffer;
if (this.serialApiGte("7.0")) {
if (this.sdkVersionGte("7.0")) {
targetNVM = await this.backupNVMRaw700(convertProgress);
} else {
targetNVM = await this.backupNVMRaw500(convertProgress);
}
const convertedNVM = migrateNVM(nvmData, targetNVM);

this.driver.controllerLog.print("Restoring NVM backup...");
if (this.serialApiGte("7.0")) {
if (this.sdkVersionGte("7.0")) {
await this.restoreNVMRaw700(convertedNVM, restoreProgress);
} else {
await this.restoreNVMRaw500(convertedNVM, restoreProgress);
Expand Down Expand Up @@ -4725,7 +4721,7 @@ ${associatedNodes.join(", ")}`,
}

try {
if (this.serialApiGte("7.0")) {
if (this.sdkVersionGte("7.0")) {
await this.restoreNVMRaw700(nvmData, onProgress);
} else {
await this.restoreNVMRaw500(nvmData, onProgress);
Expand Down
4 changes: 2 additions & 2 deletions packages/zwave-js/src/lib/controller/Features.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { SerialAPIVersion } from "./Controller";
import type { SDKVersion } from "./Controller";

/** A named list of Z-Wave features */
export enum ZWaveFeature {
// Available starting with Z-Wave SDK 6.81
SmartStart,
}

export const minFeatureVersions: Record<ZWaveFeature, SerialAPIVersion> = {
export const minFeatureVersions: Record<ZWaveFeature, SDKVersion> = {
[ZWaveFeature.SmartStart]: "6.81",
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@ export class GetControllerVersionResponse extends Message {
super(driver, options);

// The payload consists of a zero-terminated string and a uint8 for the controller type
this._libraryVersion = cpp2js(this.payload.toString("ascii"));
this._controllerType = this.payload[this.libraryVersion.length + 1];
this._sdkVersion = cpp2js(this.payload.toString("ascii"));
this._controllerType = this.payload[this.sdkVersion.length + 1];
}

private _controllerType: ZWaveLibraryTypes;
public get controllerType(): ZWaveLibraryTypes {
return this._controllerType;
}

private _libraryVersion: string;
public get libraryVersion(): string {
return this._libraryVersion;
private _sdkVersion: string;
public get sdkVersion(): string {
return this._sdkVersion;
}

public toJSON(): JSONObject {
return super.toJSONInherited({
controllerType: this.controllerType,
libraryVersion: this.libraryVersion,
sdkVersion: this.sdkVersion,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class GetSerialApiCapabilitiesResponse extends Message {
super(driver, options);

// The first 8 bytes are the api version, manufacturer id, product type and product id
this._serialApiVersion = `${this.payload[0]}.${this.payload[1]}`;
this._firmwareVersion = `${this.payload[0]}.${this.payload[1]}`;
this._manufacturerId = this.payload.readUInt16BE(2);
this._productType = this.payload.readUInt16BE(4);
this._productId = this.payload.readUInt16BE(6);
Expand All @@ -38,9 +38,9 @@ export class GetSerialApiCapabilitiesResponse extends Message {
this._supportedFunctionTypes = parseBitMask(functionBitMask);
}

private _serialApiVersion: string;
public get serialApiVersion(): string {
return this._serialApiVersion;
private _firmwareVersion: string;
public get firmwareVersion(): string {
return this._firmwareVersion;
}

private _manufacturerId: number;
Expand All @@ -65,7 +65,7 @@ export class GetSerialApiCapabilitiesResponse extends Message {

public toJSON(): JSONObject {
return super.toJSONInherited({
serialApiVersion: this.serialApiVersion,
firmwareVersion: this.firmwareVersion,
manufacturerId: this.manufacturerId,
productType: this.productType,
productId: this.productId,
Expand Down

0 comments on commit 9681323

Please sign in to comment.