diff --git a/docs/guide/mqtt.md b/docs/guide/mqtt.md index 3bc774235a..96643ad6f1 100644 --- a/docs/guide/mqtt.md +++ b/docs/guide/mqtt.md @@ -77,7 +77,7 @@ This are the available apis: - `isFailedNode(nodeId)`: Checks if a node is failed - `removeFailedNode(nodeId)`: Remove a failed node - `refreshInfo(nodeId)`: Re-interview a node to fetch its info and supported CCs -- `beginFirmwareUpdate(nodeId, fileName, data)`: Starts a firmware update of a node. The `fileName` is used to check the extension (used to detect the firmware file type) and data is a `Buffer` +- `beginFirmwareUpdate(nodeId, fileName, data, target)`: Starts a firmware update of a node. The `fileName` is used to check the extension (used to detect the firmware file type) and data is a `Buffer` - `abortFirmwareUpdate(nodeId)`: Aborts a firmware update - `writeValue(valueId, value)`: Write a specific value to a [valueId](https://zwave-js.github.io/node-zwave-js/#/api/valueid?id=valueid) - `sendCommand(valueId, command, args)`: Send a custom command diff --git a/lib/ZwaveClient.js b/lib/ZwaveClient.js index 8822b0bf7d..e4055198dd 100644 --- a/lib/ZwaveClient.js +++ b/lib/ZwaveClient.js @@ -2217,12 +2217,14 @@ ZwaveClient.prototype.refreshInfo = async function (nodeId) { * @param {number} nodeId * @param {string} fileName * @param {Buffer} data + * @param {number} target * @returns {Promise} */ ZwaveClient.prototype.beginFirmwareUpdate = async function ( nodeId, fileName, - data + data, + target ) { if (this.driver && !this.closed) { const zwaveNode = this.getNode(nodeId) @@ -2243,6 +2245,10 @@ ZwaveClient.prototype.beginFirmwareUpdate = async function ( throw Error('Unable to extract firmware from file: ' + e.message) } + if (target >= 0) { + actualFirmware.target = target + } + return zwaveNode.beginFirmwareUpdate( actualFirmware.data, actualFirmware.firmwareTarget diff --git a/src/components/Confirm.vue b/src/components/Confirm.vue index ceba3e4a73..fa7a23180e 100644 --- a/src/components/Confirm.vue +++ b/src/components/Confirm.vue @@ -14,42 +14,57 @@ }} - - - - - - - + + + + + + + + + + @@ -98,6 +113,7 @@ export default { dialog: false, resolve: null, reject: null, + valid: true, message: null, values: {}, title: null, @@ -140,13 +156,21 @@ export default { }) }, agree () { - this.dialog = false - this.resolve(this.options.inputs ? this.values : true) - this.reset() + if (this.options.inputs) { + if (this.$refs.form.validate()) { + this.dialog = false + this.resolve(this.values) + this.reset() + } + } else { + this.dialog = false + this.resolve(true) + this.reset() + } }, cancel () { this.dialog = false - this.resolve(false) + this.resolve(this.options.inputs ? {} : false) this.reset() }, reset () { diff --git a/src/components/ControlPanel.vue b/src/components/ControlPanel.vue index b6dfad8258..44abd40d70 100644 --- a/src/components/ControlPanel.vue +++ b/src/components/ControlPanel.vue @@ -289,10 +289,32 @@ export default { return } } else if (this.cnt_action === 'beginFirmwareUpdate') { + const { target } = await this.$listeners.showConfirm( + 'Choose target', + '', + 'info', + { + confirmText: 'Ok', + inputs: [ + { + type: 'number', + label: 'Target', + default: 0, + rules: [v => v >= 0 || 'Invalid target'], + hint: + 'The firmware target (i.e. chip) to upgrade. 0 updates the Z-Wave chip, >=1 updates others if they exist', + required: true, + key: 'target' + } + ] + } + ) + try { const { data, file } = await this.$listeners.import('buffer') args.push(file.name) args.push(data) + args.push(target) } catch (error) { return } diff --git a/src/components/nodes-table/NodeDetails.vue b/src/components/nodes-table/NodeDetails.vue index b6a91fd3b2..5887971dfc 100644 --- a/src/components/nodes-table/NodeDetails.vue +++ b/src/components/nodes-table/NodeDetails.vue @@ -193,10 +193,31 @@ export default { const args = [this.node.id] if (this.node_action === 'beginFirmwareUpdate') { + const { target } = await this.$listeners.showConfirm( + 'Choose target', + '', + 'info', + { + confirmText: 'Ok', + inputs: [ + { + type: 'number', + label: 'Target', + default: 0, + rules: [v => v >= 0 || 'Invalid target'], + hint: + 'The firmware target (i.e. chip) to upgrade. 0 updates the Z-Wave chip, >=1 updates others if they exist', + required: true, + key: 'target' + } + ] + } + ) try { const { data, file } = await this.$listeners.import('buffer') args.push(file.name) args.push(data) + args.push(target) } catch (error) { return } diff --git a/types/index.d.ts b/types/index.d.ts index d31fbacae8..e1b1840c4b 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -371,7 +371,8 @@ export interface ZwaveClient extends EventEmitter { beginFirmwareUpdate( nodeId: number, fileName: string, - data: Buffer + data: Buffer, + target: number | undefined ): Promise abortFirmwareUpdate(nodeId: number): Promise beginHealingNetwork(): Promise