Skip to content

Commit

Permalink
feat: allow to restore NVM raw (#3337)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando authored Oct 12, 2023
1 parent a16b962 commit 0b8f33f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
19 changes: 13 additions & 6 deletions lib/ZwaveClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4735,16 +4735,23 @@ class ZwaveClient extends TypedEventEmitter<ZwaveClientEventCallbacks> {
this._updateControllerStatus(`Backup NVM progress: ${progress}%`)
}

async restoreNVM(data: Buffer) {
async restoreNVM(data: Buffer, useRaw = false) {
if (!this.driverReady) {
throw new DriverNotReadyError()
}

await this.driver.controller.restoreNVM(
data,
this._onConvertNVMProgress.bind(this),
this._onRestoreNVMProgress.bind(this)
)
if (useRaw) {
await this.driver.controller.restoreNVMRaw(
data,
this._onRestoreNVMProgress.bind(this)
)
} else {
await this.driver.controller.restoreNVM(
data,
this._onConvertNVMProgress.bind(this),
this._onRestoreNVMProgress.bind(this)
)
}
}

private _onConvertNVMProgress(bytesRead: number, totalBytes: number) {
Expand Down
23 changes: 19 additions & 4 deletions src/views/ControlPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -789,21 +789,36 @@ export default {
return
}
} else if (action === 'restoreNVM') {
const confirm = await this.$listeners.showConfirm(
const result = await this.$listeners.showConfirm(
'NVM Restore',
'While doing the restore the Z-Wave radio will be turned on/off.\n<strong>A failure during this process may brick your controller. Use at your own risk!</strong>',
'alert',
{
confirmText: 'Ok',
width: 500,
inputs: [
{
type: 'file',
label: 'File',
hint: 'NVM file',
key: 'file',
},
{
type: 'checkbox',
label: 'Skip compatibility check',
hint: 'This needs to be checked in order to allow restoring NVM backups on older controllers, with the risk of restoring an incompatible backup',
key: 'useRaw',
},
],
}
)
if (!confirm) {
if (!result?.file) {
return
}
try {
const { data } = await this.$listeners.import('buffer')
args.push(data)
const data = await result.file.arrayBuffer()
args.push(data, result.useRaw)
} catch (error) {
return
}
Expand Down

0 comments on commit 0b8f33f

Please sign in to comment.