diff --git a/hassio/src/system/hassio-host-info.ts b/hassio/src/system/hassio-host-info.ts index 60256bbe64..06521b7076 100644 --- a/hassio/src/system/hassio-host-info.ts +++ b/hassio/src/system/hassio-host-info.ts @@ -1,5 +1,4 @@ import "@material/mwc-button"; -import { ActionDetail } from "@material/mwc-list/mwc-list-foundation"; import "@material/mwc-list/mwc-list-item"; import { mdiDotsVertical } from "@mdi/js"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; @@ -19,6 +18,7 @@ import { fetchHassioHardwareInfo } from "../../../src/data/hassio/hardware"; import { changeHostOptions, configSyncOS, + dataDiskMove, rebootHost, shutdownHost, updateOS, @@ -180,21 +180,27 @@ class HassioHostInfo extends LitElement { ` : ""} - + - + this._handleMenuAction("hardware")}> ${this.supervisor.localize("system.host.hardware")} ${this.supervisor.host.features.includes("haos") - ? html` + ? html` this._handleMenuAction("import_from_usb")} + > ${this.supervisor.localize("system.host.import_from_usb")} ` : ""} + ${this.supervisor.host.features.includes("agent") + ? html` this._handleMenuAction("data_disk_move")} + > + ${this.supervisor.localize("system.host.data_disk_move")} + ` + : ""} @@ -216,14 +222,17 @@ class HassioHostInfo extends LitElement { return network_info.interfaces.find((a) => a.primary)?.ipv4?.address![0]; }); - private async _handleMenuAction(ev: CustomEvent) { - switch (ev.detail.index) { - case 0: + private async _handleMenuAction(action: string) { + switch (action) { + case "hardware": await this._showHardware(); break; - case 1: + case "import_from_usb": await this._importFromUSB(); break; + case "data_disk_move": + await this._dataDiskMove(); + break; } } @@ -395,6 +404,34 @@ class HassioHostInfo extends LitElement { } } + private async _dataDiskMove(): Promise { + const confirmed = await showConfirmationDialog(this, { + title: this.supervisor.localize("system.host.data_disk_move"), + text: html`${this.supervisor.localize( + "dialog.data_disk_move.description", + { current_path: this.supervisor.os.data_disk } + )}

${this.supervisor.localize( + "dialog.data_disk_move.confirm_text" + )}`, + confirmText: this.supervisor.localize("dialog.data_disk_move.move"), + dismissText: this.supervisor.localize("dialog.data_disk_move.cancel"), + }); + if (!confirmed) { + return; + } + + try { + await dataDiskMove(this.hass); + } catch (err) { + if (this.hass.connection.connected && !ignoreSupervisorError(err)) { + showAlertDialog(this, { + title: this.supervisor.localize("system.host.failed_to_move"), + text: extractApiErrorMessage(err), + }); + } + } + } + private async _loadData(): Promise { if (atLeastVersion(this.hass.config.version, 2021, 2, 4)) { fireEvent(this, "supervisor-collection-refresh", { diff --git a/src/data/hassio/host.ts b/src/data/hassio/host.ts index 47d5d8f815..568f488450 100644 --- a/src/data/hassio/host.ts +++ b/src/data/hassio/host.ts @@ -22,6 +22,7 @@ export interface HassioHassOSInfo { update_available: boolean; version_latest: string | null; version: string | null; + data_disk: string; } export const fetchHassioHostInfo = async ( @@ -113,6 +114,19 @@ export const configSyncOS = async (hass: HomeAssistant) => { return hass.callApi>("POST", "hassio/os/config/sync"); }; +export const dataDiskMove = async (hass: HomeAssistant) => { + if (atLeastVersion(hass.config.version, 2021, 2, 4)) { + return hass.callWS({ + type: "supervisor/api", + endpoint: "/os/datadisk/move", + method: "post", + timeout: null, + }); + } + + return hass.callApi>("POST", "hassio/os/datadisk/move"); +}; + export const changeHostOptions = async (hass: HomeAssistant, options: any) => { if (atLeastVersion(hass.config.version, 2021, 2, 4)) { return hass.callWS({ diff --git a/src/translations/en.json b/src/translations/en.json index 92529a281c..bd411c7cdc 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -4099,6 +4099,7 @@ "failed_to_shutdown": "Failed to shutdown the host", "failed_to_set_hostname": "Setting hostname failed", "failed_to_import_from_usb": "Failed to import from USB", + "failed_to_move": "Failed to move data disk", "used_space": "Used space", "hostname": "Hostname", "change_hostname": "Change Hostname", @@ -4114,7 +4115,8 @@ "confirm_shutdown": "Are you sure you want to shutdown the host?", "shutdown_host": "Shutdown host", "hardware": "Hardware", - "import_from_usb": "Import from USB" + "import_from_usb": "Import from USB", + "data_disk_move": "Move to data disk" }, "core": { "cpu_usage": "Core CPU Usage", @@ -4201,6 +4203,12 @@ "id": "ID", "attributes": "Attributes", "device_path": "Device path" + }, + "data_disk_move": { + "description": "The current path to the data disk is ''{current_path}'', moving the disk will require a reboot of the host which will be done automatically.", + "confirm_text": "Do you want to move now?", + "cancel": "[%key:ui::common::cancel%]", + "move": "Move" } } }