Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only serialize Firmware Update hardware version if defined #7452

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ export class FirmwareUpdateMetaDataCCRequestGet
public nonSecureTransfer?: boolean;

public serialize(ctx: CCEncodingContext): Bytes {
this.payload = Bytes.alloc(11, 0);
this.payload = Bytes.alloc(10, 0);
this.payload.writeUInt16BE(this.manufacturerId, 0);
this.payload.writeUInt16BE(this.firmwareId, 2);
this.payload.writeUInt16BE(this.checksum, 4);
Expand All @@ -678,7 +678,13 @@ export class FirmwareUpdateMetaDataCCRequestGet
this.payload[9] = (this.activation ? 0b1 : 0)
| (this.nonSecureTransfer ? 0b10 : 0)
| (this.resume ? 0b100 : 0);
this.payload[10] = this.hardwareVersion ?? 0x00;
// Hardware version is not always set, but devices check it
if (this.hardwareVersion != undefined) {
this.payload = Bytes.concat([
this.payload,
[this.hardwareVersion],
]);
}

// eslint-disable-next-line @typescript-eslint/no-deprecated
return super.serialize(ctx);
Expand Down Expand Up @@ -1030,12 +1036,17 @@ export class FirmwareUpdateMetaDataCCActivationSet
public hardwareVersion?: number;

public serialize(ctx: CCEncodingContext): Bytes {
this.payload = new Bytes(8);
this.payload = new Bytes(7);
this.payload.writeUInt16BE(this.manufacturerId, 0);
this.payload.writeUInt16BE(this.firmwareId, 2);
this.payload.writeUInt16BE(this.checksum, 4);
this.payload[6] = this.firmwareTarget;
this.payload[7] = this.hardwareVersion ?? 0x00;
if (this.hardwareVersion != undefined) {
this.payload = Bytes.concat([
this.payload,
[this.hardwareVersion],
]);
}
// eslint-disable-next-line @typescript-eslint/no-deprecated
return super.serialize(ctx);
}
Expand Down
9 changes: 7 additions & 2 deletions packages/zwave-js/src/lib/node/mixins/70_FirmwareUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export abstract class FirmwareUpdateMixin extends SchedulePollMixin
// Prepare the firmware update
let fragmentSizeSecure: number;
let fragmentSizeNonSecure: number;
let hardwareVersion: number | undefined;
let meta: FirmwareUpdateMetaData;
try {
const prepareResult = await self
Expand Down Expand Up @@ -250,6 +251,7 @@ export abstract class FirmwareUpdateMixin extends SchedulePollMixin
({
fragmentSizeSecure,
fragmentSizeNonSecure,
hardwareVersion,
...meta
} = prepareResult!);
} catch {
Expand Down Expand Up @@ -353,6 +355,7 @@ export abstract class FirmwareUpdateMixin extends SchedulePollMixin
meta,
fragmentSize,
checksum,
hardwareVersion,
shouldResume,
options.nonSecureTransfer,
);
Expand Down Expand Up @@ -646,8 +649,9 @@ export abstract class FirmwareUpdateMixin extends SchedulePollMixin
meta: FirmwareUpdateMetaData,
fragmentSize: number,
checksum: number,
resume: boolean | undefined,
nonSecureTransfer: boolean | undefined,
hardwareVersion?: number,
resume?: boolean,
nonSecureTransfer?: boolean,
) {
const api = this.commandClasses["Firmware Update Meta Data"];

Expand All @@ -669,6 +673,7 @@ export abstract class FirmwareUpdateMixin extends SchedulePollMixin
firmwareTarget: target,
fragmentSize,
checksum,
hardwareVersion,
resume,
nonSecureTransfer,
});
Expand Down
Loading