Skip to content
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
6 changes: 5 additions & 1 deletion src/data/zwave_js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -757,10 +757,14 @@ export const fetchZwaveNodeFirmwareUpdateCapabilities = (
export const uploadFirmwareAndBeginUpdate = async (
hass: HomeAssistant,
device_id: string,
file: File
file: File,
target?: number
) => {
const fd = new FormData();
fd.append("file", file);
if (target !== undefined) {
fd.append("target", target.toString());
}
const resp = await hass.fetchWithAuth(
`/api/zwave_js/firmware/upload/${device_id}`,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ import {
showAlertDialog,
showConfirmationDialog,
} from "../../../../../dialogs/generic/show-dialog-box";
import { HaFormSchema } from "../../../../../components/ha-form/types";

const firmwareTargetSchema: HaFormSchema[] = [
{
name: "firmware_target",
type: "integer",
valueMin: 0,
},
];

@customElement("dialog-zwave_js-update-firmware-node")
class DialogZWaveJSUpdateFirmwareNode extends LitElement {
Expand All @@ -59,6 +68,8 @@ class DialogZWaveJSUpdateFirmwareNode extends LitElement {

@state() private _nodeStatus?: ZWaveJSNodeStatus;

@state() private _firmwareTarget?: number;

private _subscribedNodeStatus?: Promise<UnsubscribeFunc>;

private _subscribedNodeFirmwareUpdate?: Promise<UnsubscribeFunc>;
Expand All @@ -80,6 +91,7 @@ class DialogZWaveJSUpdateFirmwareNode extends LitElement {
this._updateFinishedMessage = undefined;
this._firmwareFile = undefined;
this._nodeStatus = undefined;
this._firmwareTarget = undefined;
this._uploading = this._updateInProgress = false;

fireEvent(this, "dialog-closed", { dialog: this.localName });
Expand All @@ -104,6 +116,19 @@ class DialogZWaveJSUpdateFirmwareNode extends LitElement {
)}
@file-picked=${this._uploadFile}
></ha-file-upload>
${this._nodeStatus.is_controller_node
? html``
: html`<p>
${this.hass.localize(
"ui.panel.config.zwave_js.update_firmware.firmware_target_intro"
)}
</p>
<ha-form
.hass=${this.hass}
.data=${{ firmware_target: this._firmwareTarget }}
.schema=${firmwareTargetSchema}
@value-changed=${this._firmwareTargetChanged}
></ha-form>`}
<mwc-button
slot="primaryAction"
@click=${this._beginFirmwareUpdate}
Expand Down Expand Up @@ -283,7 +308,8 @@ class DialogZWaveJSUpdateFirmwareNode extends LitElement {
await uploadFirmwareAndBeginUpdate(
this.hass,
this.device!.id,
this._firmwareFile!
this._firmwareFile!,
this._firmwareTarget
);
this._updateInProgress = true;
this._uploading = false;
Expand Down Expand Up @@ -388,6 +414,10 @@ class DialogZWaveJSUpdateFirmwareNode extends LitElement {
this._subscribedNodeFirmwareUpdate = undefined;
}

private async _firmwareTargetChanged(ev) {
this._firmwareTarget = ev.detail.value.firmware_target;
}

private async _uploadFile(ev) {
this._firmwareFile = ev.detail.files[0];
}
Expand Down
2 changes: 2 additions & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3691,6 +3691,8 @@
"warning_controller": "WARNING: Firmware updates can brick your controller if you do not use the right firmware files, or if you attempt to stop the firmware update before it completes. The Home Assistant and Z-Wave JS teams do not take any responsibility for any damages to your controller as a result of the firmware update and will not be able to help you if you brick your controller. Would you still like to continue?",
"introduction": "Select the firmware file you would like to use to update {device}.",
"introduction_controller": "Select the firmware file you would like to use to update {device}. Note that once you start a firmware update, you MUST wait for the update to complete.",
"firmware_target_intro": "Select the firmware target (0 for the Z-Wave chip, ≥1 for other chips if they exist) for this update.",
"firmware_target": "Firmware Target (chip)",
"upload_firmware": "Upload Firmware",
"upload_failed": "Upload Failed",
"begin_update": "Begin Firmware Update",
Expand Down