Skip to content

Commit

Permalink
feat: add driver option to configure vendor-specific constants (#6876)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone authored Jun 10, 2024
1 parent 170d51b commit 5feb4ab
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
3 changes: 1 addition & 2 deletions packages/cc/src/cc/VersionCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,7 @@ export class VersionCCReport extends VersionCC {
.split(".")
.map((n) => parseInt(n))
.slice(0, 2),
// The value 0x00 SHOULD NOT be used for the Hardware Version
this.hardwareVersion ?? 0x01,
this.hardwareVersion ?? 0x00,
this.firmwareVersions.length - 1,
]);

Expand Down
1 change: 1 addition & 0 deletions packages/zwave-js/src/lib/driver/Driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,7 @@ export class Driver extends TypedEventEmitter<DriverEventCallbacks>
"inclusionUserCallbacks",
"interview",
"preferences",
"vendor",
]);

// Create a new deep-merged copy of the options so we can check them for validity
Expand Down
20 changes: 19 additions & 1 deletion packages/zwave-js/src/lib/driver/ZWaveOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,23 @@ export interface ZWaveOptions extends ZWaveHostOptions {
*/
userAgent?: Record<string, string>;

/**
* Specify application-specific information to use in queries from other devices
*/
vendor?: {
manufacturerId: number;
productType: number;
productId: number;

/** The version of the hardware the application is running on. Can be omitted if unknown. */
hardwareVersion?: number;

/** The icon type to use for installers. Default: 0x0500 - Generic Gateway */
installerIcon?: number;
/** The icon type to use for users. Default: 0x0500 - Generic Gateway */
userIcon?: number;
};

/** DO NOT USE! Used for testing internally */
testingHooks?: {
serialPortBinding?: typeof SerialPort;
Expand Down Expand Up @@ -361,7 +378,7 @@ export type PartialZWaveOptions = Expand<
& Partial<
Pick<
ZWaveOptions,
"inclusionUserCallbacks" | "testingHooks"
"inclusionUserCallbacks" | "testingHooks" | "vendor"
>
>
& {
Expand All @@ -379,6 +396,7 @@ export type EditableZWaveOptions = Expand<
| "interview"
| "logConfig"
| "preferences"
| "vendor"
>
& {
userAgent?: Record<string, string | null | undefined>;
Expand Down
18 changes: 11 additions & 7 deletions packages/zwave-js/src/lib/node/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3988,8 +3988,9 @@ protocol version: ${this.protocolVersion}`;
zwavePlusVersion: 2,
roleType: ZWavePlusRoleType.CentralStaticController,
nodeType: ZWavePlusNodeType.Node,
installerIcon: 0x0500, // Generic Gateway // FIXME: Make configurable
userIcon: 0x0500, // Generic Gateway
installerIcon: this.driver.options.vendor?.installerIcon
?? 0x0500, // Generic Gateway
userIcon: this.driver.options.vendor?.userIcon ?? 0x0500, // Generic Gateway
});
}

Expand All @@ -4011,6 +4012,7 @@ protocol version: ${this.protocolVersion}`;
libraryType: ZWaveLibraryTypes["Static Controller"],
protocolVersion: this.driver.controller.protocolVersion!,
firmwareVersions: [this.driver.controller.firmwareVersion!],
hardwareVersion: this.driver.options.vendor?.hardwareVersion,
});
}

Expand Down Expand Up @@ -4067,9 +4069,10 @@ protocol version: ${this.protocolVersion}`;
});

await api.sendReport({
manufacturerId: 0x0466, // Nabu Casa - FIXME: make dynamic!
productType: 0x0000,
productId: 0x0000,
manufacturerId: this.driver.options.vendor?.manufacturerId
?? 0xffff, // Reserved manufacturer ID, definitely invalid!
productType: this.driver.options.vendor?.productType ?? 0xffff,
productId: this.driver.options.vendor?.productId ?? 0xffff,
});
}

Expand Down Expand Up @@ -6160,9 +6163,10 @@ protocol version: ${this.protocolVersion}`;

// We do not support the firmware to be upgraded.
await api.reportMetaData({
manufacturerId: 0x0466, // Nabu Casa - FIXME: Make this configurable
manufacturerId: this.driver.options.vendor?.manufacturerId
?? 0xffff,
firmwareUpgradable: false,
hardwareVersion: 1, // FIXME: Make configurable, must be the same as in Version CC
hardwareVersion: this.driver.options.vendor?.hardwareVersion ?? 0,
});
}

Expand Down

0 comments on commit 5feb4ab

Please sign in to comment.