From 3d06a1bca5d501b5f80aabacac2ccd9d58f3825a Mon Sep 17 00:00:00 2001 From: AlCalzone Date: Thu, 6 Feb 2025 13:04:26 +0100 Subject: [PATCH] feat: expose firmware ID for OTA update to applications (#7599) --- docs/api/node.md | 4 ++- packages/core/src/util/_Types.ts | 1 + .../src/lib/node/mixins/70_FirmwareUpdate.ts | 26 ++++++++++++------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/docs/api/node.md b/docs/api/node.md index 36e768a04fa0..7d302bd7002e 100644 --- a/docs/api/node.md +++ b/docs/api/node.md @@ -352,7 +352,8 @@ Performs an OTA firmware update process for this node, applying the provided fir This method an array of firmware updates, each of which contains the following properties: - `data` - A buffer containing the firmware image in a format supported by the device -- `target` - _(optional)_ The firmware target (i.e. chip) to upgrade. `0` updates the Z-Wave chip, `>=1` updates others if they exist +- `firmwareTarget` - _(optional)_ The firmware target (i.e. chip) to upgrade. `0` updates the Z-Wave chip, `>=1` updates others if they exist +- `firmwareId` - _(optional)_ The ID of the new firmware that will be uploaded. This is only necessary if the device checks the firmware ID before starting the update. If not given, the current firmware ID will be reused. @@ -360,6 +361,7 @@ This method an array of firmware updates, each of which contains the following p interface Firmware { data: Uint8Array; firmwareTarget?: number; + firmwareId?: number; } ``` diff --git a/packages/core/src/util/_Types.ts b/packages/core/src/util/_Types.ts index e58f97c45785..dea50918f88e 100644 --- a/packages/core/src/util/_Types.ts +++ b/packages/core/src/util/_Types.ts @@ -10,4 +10,5 @@ export type FirmwareFileFormat = export interface Firmware { data: Uint8Array; firmwareTarget?: number; + firmwareId?: number; } diff --git a/packages/zwave-js/src/lib/node/mixins/70_FirmwareUpdate.ts b/packages/zwave-js/src/lib/node/mixins/70_FirmwareUpdate.ts index 8691c03b43ea..98a5fef52735 100644 --- a/packages/zwave-js/src/lib/node/mixins/70_FirmwareUpdate.ts +++ b/packages/zwave-js/src/lib/node/mixins/70_FirmwareUpdate.ts @@ -319,8 +319,16 @@ export abstract class FirmwareUpdateMixin extends SchedulePollMixin let sentBytesOfPreviousFiles = 0; for (let i = 0; i < updatesWithChecksum.length; i++) { - const { firmwareTarget: target = 0, data, checksum } = - updatesWithChecksum[i]; + const { + // If the firmware target is not given, update the Z-Wave chip + firmwareTarget: target = 0, + // If the firmware ID is not given, use the current one for the given chip + firmwareId = target === 0 + ? meta.firmwareId + : meta.additionalFirmwareIDs[target - 1], + data, + checksum, + } = updatesWithChecksum[i]; if (i < skipFinishedFiles) { // If we are resuming, skip this file since it was already done before @@ -351,8 +359,9 @@ export abstract class FirmwareUpdateMixin extends SchedulePollMixin const { resume, nonSecureTransfer } = yield* self .beginFirmwareUpdateInternal( data, + meta.manufacturerId, target, - meta, + firmwareId, fragmentSize, checksum, hardwareVersion, @@ -645,8 +654,9 @@ export abstract class FirmwareUpdateMixin extends SchedulePollMixin /** Kicks off a firmware update of a single target. Returns whether the node accepted resuming and non-secure transfer */ private async *beginFirmwareUpdateInternal( data: Uint8Array, + manufacturerId: number, target: number, - meta: FirmwareUpdateMetaData, + firmwareId: number, fragmentSize: number, checksum: number, hardwareVersion?: number, @@ -665,11 +675,9 @@ export abstract class FirmwareUpdateMixin extends SchedulePollMixin // Request the node to start the upgrade await api.requestUpdate({ - // TODO: Should manufacturer id and firmware id be provided externally? - manufacturerId: meta.manufacturerId, - firmwareId: target == 0 - ? meta.firmwareId - : meta.additionalFirmwareIDs[target - 1], + // TODO: Should manufacturer id be provided externally? + manufacturerId, + firmwareId, firmwareTarget: target, fragmentSize, checksum,