Skip to content

Commit

Permalink
fix(ui): show OTA result (#3360)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando authored Oct 18, 2023
1 parent b0e6d2c commit 39f09bd
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 96 deletions.
91 changes: 90 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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 =
'<p>The firmware must be activated <b>manually</b>, likely by pushing a button on the device.</p>'
} else if (
result.status === FirmwareUpdateStatus.OK_RestartPending
) {
message = `<p>The device will now restart.${
result.waitTime
? ` This will take approximately <b>${result.waitTime}</b> seconds.`
: ''
}</p>`
} else if (
// status is OK_NoRestart
result.waitTime &&
!result.reInterview
) {
message = `<p>Please wait <b>${result.waitTime}</b> seconds before interacting with the device again.<p>`
}
if (result.reInterview) {
if (result.waitTime) {
message +=
'<p>Afterwards the device will be <b>re-interviewed</b>.<p>'
} else {
message +=
'<p>The device will now be <b>re-interviewed</b>.<p>'
}
message +=
'<p>Wait until the interview is done before interacting with the device again.<p/>'
}
} 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(
Expand Down
7 changes: 6 additions & 1 deletion src/components/nodes-table/OTAUpdates.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
},
},
Expand Down
96 changes: 2 additions & 94 deletions src/views/ControlPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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 =
'<p>The firmware must be activated <b>manually</b>, likely by pushing a button on the device.</p>'
} else if (
result.status ===
FirmwareUpdateStatus.OK_RestartPending
) {
message = `<p>The device will now restart.${
result.waitTime
? ` This will take approximately <b>${result.waitTime}</b> seconds.`
: ''
}</p>`
} else if (
// status is OK_NoRestart
result.waitTime &&
!result.reInterview
) {
message = `<p>Please wait <b>${result.waitTime}</b> seconds before interacting with the device again.<p>`
}
if (result.reInterview) {
if (result.waitTime) {
message +=
'<p>Afterwards the device will be <b>re-interviewed</b>.<p>'
} else {
message +=
'<p>The device will now be <b>re-interviewed</b>.<p>'
}
message +=
'<p>Wait until the interview is done before interacting with the device again.<p/>'
}
} 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`,
Expand Down

0 comments on commit 39f09bd

Please sign in to comment.