From bf5a4ef711d085da60f46daccaabe33fc986ca2c Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Wed, 18 Oct 2023 16:14:26 +0200 Subject: [PATCH] fix(ui): show OTA result Fixes #3341 --- src/App.vue | 91 ++++++++++++++++++++- src/components/nodes-table/OTAUpdates.vue | 7 +- src/views/ControlPanel.vue | 96 +---------------------- 3 files changed, 98 insertions(+), 96 deletions(-) diff --git a/src/App.vue b/src/App.vue index 803cc5eaba6..e80d444fc14 100644 --- a/src/App.vue +++ b/src/App.vue @@ -392,7 +392,11 @@ import { socketEvents, inboundEvents as socketActions, } from '@server/lib/SocketEvents' -import { getEnumMemberName, SecurityBootstrapFailure } from 'zwave-js/safe' +import { + getEnumMemberName, + SecurityBootstrapFailure, + FirmwareUpdateStatus, +} from 'zwave-js/safe' import DialogNodesManager from '@/components/dialogs/DialogNodesManager.vue' let socketQueue = [] @@ -1079,6 +1083,91 @@ export default { log.error(error) } }, + async handleFwUpdateResponse(response) { + const result = response.result + + const title = `Firmware update ${ + result.success ? 'success' : 'failed' + }` + + let message = '' + + if (result.success) { + if ( + result.status === + FirmwareUpdateStatus.OK_WaitingForActivation + ) { + message = + '

The firmware must be activated manually, likely by pushing a button on the device.

' + } else if ( + result.status === FirmwareUpdateStatus.OK_RestartPending + ) { + message = `

The device will now restart.${ + result.waitTime + ? ` This will take approximately ${result.waitTime} seconds.` + : '' + }

` + } else if ( + // status is OK_NoRestart + result.waitTime && + !result.reInterview + ) { + message = `

Please wait ${result.waitTime} seconds before interacting with the device again.

` + } + + if (result.reInterview) { + if (result.waitTime) { + message += + '

Afterwards the device will be re-interviewed.

' + } else { + message += + '

The device will now be re-interviewed.

' + } + + message += + '

Wait until the interview is done before interacting with the device again.

' + } + } else { + switch (result.status) { + case FirmwareUpdateStatus.Error_Timeout: + message = + 'There was a timeout during the firmware update.' + break + case FirmwareUpdateStatus.Error_Checksum: + message = 'Invalid checksum' + break + case FirmwareUpdateStatus.Error_TransmissionFailed: + message = 'The transmission failed or was aborted' + break + case FirmwareUpdateStatus.Error_InvalidManufacturerID: + message = 'The manufacturer ID is invalid' + break + case FirmwareUpdateStatus.Error_InvalidFirmwareID: + message = 'The firmware ID is invalid' + break + case FirmwareUpdateStatus.Error_InvalidFirmwareTarget: + message = 'The firmware target is invalid' + break + case FirmwareUpdateStatus.Error_InvalidHeaderInformation: + case FirmwareUpdateStatus.Error_InvalidHeaderFormat: + message = 'The firmware header is invalid' + break + case FirmwareUpdateStatus.Error_InsufficientMemory: + message = + 'The device does not have enough memory to perform the firmware update' + break + case FirmwareUpdateStatus.Error_InvalidHardwareVersion: + message = 'The hardware version is invalid' + break + } + } + + this.confirm(title, message, 'info', { + confirmText: 'Ok', + noCancel: true, + color: result.success ? 'success' : 'error', + }) + }, async getRelease(project, version) { try { const response = await fetch( diff --git a/src/components/nodes-table/OTAUpdates.vue b/src/components/nodes-table/OTAUpdates.vue index 14472ae67e7..e453b9e92ff 100644 --- a/src/components/nodes-table/OTAUpdates.vue +++ b/src/components/nodes-table/OTAUpdates.vue @@ -216,7 +216,12 @@ export default { }, ) ) { - this.app.apiRequest('firmwareUpdateOTA', [this.node.id, update]) + const response = await this.app.apiRequest( + 'firmwareUpdateOTA', + [this.node.id, update], + ) + + await this.app.handleFwUpdateResponse(response) } }, }, diff --git a/src/views/ControlPanel.vue b/src/views/ControlPanel.vue index 58f5e838047..abc9e766427 100644 --- a/src/views/ControlPanel.vue +++ b/src/views/ControlPanel.vue @@ -127,7 +127,6 @@ import { jsonToList } from '@/lib/utils' import useBaseStore from '../stores/base.js' import InstancesMixin from '../mixins/InstancesMixin.js' import logger from '../lib/logger' -import { FirmwareUpdateStatus } from 'zwave-js/safe' const log = logger.get('ControlPanel') @@ -924,100 +923,9 @@ export default { break } case 'updateFirmware': - case 'firmwareUpdateOTA': { - const result = response.result - - const title = `Firmware update ${ - result.success ? 'success' : 'failed' - }` - - let message = '' - - if (result.success) { - if ( - result.status === - FirmwareUpdateStatus.OK_WaitingForActivation - ) { - message = - '

The firmware must be activated manually, likely by pushing a button on the device.

' - } else if ( - result.status === - FirmwareUpdateStatus.OK_RestartPending - ) { - message = `

The device will now restart.${ - result.waitTime - ? ` This will take approximately ${result.waitTime} seconds.` - : '' - }

` - } else if ( - // status is OK_NoRestart - result.waitTime && - !result.reInterview - ) { - message = `

Please wait ${result.waitTime} seconds before interacting with the device again.

` - } - - if (result.reInterview) { - if (result.waitTime) { - message += - '

Afterwards the device will be re-interviewed.

' - } else { - message += - '

The device will now be re-interviewed.

' - } - - message += - '

Wait until the interview is done before interacting with the device again.

' - } - } else { - switch (result.status) { - case FirmwareUpdateStatus.Error_Timeout: - message = - 'There was a timeout during the firmware update.' - break - case FirmwareUpdateStatus.Error_Checksum: - message = 'Invalid checksum' - break - case FirmwareUpdateStatus.Error_TransmissionFailed: - message = - 'The transmission failed or was aborted' - break - case FirmwareUpdateStatus.Error_InvalidManufacturerID: - message = - 'The manufacturer ID is invalid' - break - case FirmwareUpdateStatus.Error_InvalidFirmwareID: - message = - 'The firmware ID is invalid' - break - case FirmwareUpdateStatus.Error_InvalidFirmwareTarget: - message = - 'The firmware target is invalid' - break - case FirmwareUpdateStatus.Error_InvalidHeaderInformation: - case FirmwareUpdateStatus.Error_InvalidHeaderFormat: - message = - 'The firmware header is invalid' - break - case FirmwareUpdateStatus.Error_InsufficientMemory: - message = - 'The device does not have enough memory to perform the firmware update' - break - case FirmwareUpdateStatus.Error_InvalidHardwareVersion: - message = - 'The hardware version is invalid' - break - } - } - - this.app.confirm(title, message, 'info', { - confirmText: 'Ok', - noCancel: true, - color: result.success ? 'success' : 'error', - }) - + this.app.handleFwUpdateResponse(response) break - } + default: this.showSnackbar( `API ${response.api} ended successfully`,