Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow to set custom firmware target #501

Merged
merged 2 commits into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/guide/mqtt.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion lib/ZwaveClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -2217,12 +2217,14 @@ ZwaveClient.prototype.refreshInfo = async function (nodeId) {
* @param {number} nodeId
* @param {string} fileName
* @param {Buffer} data
* @param {number} target
* @returns {Promise<void>}
*/
ZwaveClient.prototype.beginFirmwareUpdate = async function (
nodeId,
fileName,
data
data,
target
) {
if (this.driver && !this.closed) {
const zwaveNode = this.getNode(nodeId)
Expand All @@ -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
Expand Down
104 changes: 64 additions & 40 deletions src/components/Confirm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,57 @@
}}</v-card-text>
<v-card-text v-else class="pa-4">
<v-container grid-list-md>
<v-row>
<v-col
v-for="(input, index) in options.inputs"
:key="index"
cols="12"
>
<v-text-field
v-if="input.type === 'text' || input.type === 'number'"
v-model="values[input.key]"
:label="input.label"
:hint="input.hint"
:type="input.type || 'text'"
:required="input.required"
:min="input.min"
:max="input.max"
></v-text-field>
<v-switch
v-if="input.type === 'boolean'"
v-model="values[input.key]"
:label="input.label"
:hint="input.hint"
:persistent-hint="!!input.hint"
:required="input.required"
></v-switch>
<v-select
v-if="input.type === 'list'"
v-model="values[input.key]"
:item-text="input.itemText || 'text'"
:item-value="input.itemValue || 'value'"
:items="input.items"
:label="input.label"
:hint="input.hint"
:required="input.required"
></v-select>
</v-col>
</v-row>
<v-form v-model="valid" ref="form" lazy-validation>
<v-row>
<v-col
v-for="(input, index) in options.inputs"
:key="index"
cols="12"
>
<v-text-field
v-if="input.type === 'text'"
v-model.trim="values[input.key]"
:label="input.label"
:hint="input.hint"
:rules="input.rules || []"
:required="input.required"
:min="input.min"
:max="input.max"
></v-text-field>
<v-text-field
v-if="input.type === 'number'"
v-model.number="values[input.key]"
:label="input.label"
:hint="input.hint"
:rules="input.rules || []"
type="number"
:required="input.required"
:min="input.min"
:max="input.max"
></v-text-field>
<v-switch
v-if="input.type === 'boolean'"
v-model="values[input.key]"
:rules="input.rules || []"
:label="input.label"
:hint="input.hint"
:persistent-hint="!!input.hint"
:required="input.required"
></v-switch>
<v-select
v-if="input.type === 'list'"
v-model="values[input.key]"
:item-text="input.itemText || 'text'"
:item-value="input.itemValue || 'value'"
:items="input.items"
:rules="input.rules || []"
:label="input.label"
:hint="input.hint"
:required="input.required"
></v-select>
</v-col>
</v-row>
</v-form>
</v-container>
</v-card-text>

Expand Down Expand Up @@ -98,6 +113,7 @@ export default {
dialog: false,
resolve: null,
reject: null,
valid: true,
message: null,
values: {},
title: null,
Expand Down Expand Up @@ -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 () {
Expand Down
22 changes: 22 additions & 0 deletions src/components/ControlPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
21 changes: 21 additions & 0 deletions src/components/nodes-table/NodeDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ export interface ZwaveClient extends EventEmitter {
beginFirmwareUpdate(
nodeId: number,
fileName: string,
data: Buffer
data: Buffer,
target: number | undefined
): Promise<void>
abortFirmwareUpdate(nodeId: number): Promise<void>
beginHealingNetwork(): Promise<boolean>
Expand Down