Skip to content

Commit

Permalink
fix: only serialize Firmware Update hardware version if defined (#7452)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone authored Dec 2, 2024
1 parent f2d7b3e commit 18c5e0a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
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

0 comments on commit 18c5e0a

Please sign in to comment.