From 5df679f56b6d9223d8b47a848eaa4aefd3662b10 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Mon, 23 Dec 2024 11:18:56 +0100 Subject: [PATCH 1/2] Use custom icon and name for network storage --- src/data/backup.ts | 28 ++++++++++- .../config/ha-backup-config-agents.ts | 41 +++++++++++------ .../components/ha-backup-agents-picker.ts | 38 ++++++++------- .../config/backup/ha-config-backup-backups.ts | 11 +++++ .../config/backup/ha-config-backup-details.ts | 46 ++++++++++++------- 5 files changed, 116 insertions(+), 48 deletions(-) diff --git a/src/data/backup.ts b/src/data/backup.ts index 2cda20eb4919..247cf8f3be0c 100644 --- a/src/data/backup.ts +++ b/src/data/backup.ts @@ -220,6 +220,11 @@ export const CLOUD_AGENT = "cloud.cloud"; export const isLocalAgent = (agentId: string) => [CORE_LOCAL_AGENT, HASSIO_LOCAL_AGENT].includes(agentId); +export const isNetworkMountAgent = (agentId: string) => { + const [domain, name] = agentId.split("."); + return domain === "hassio" && name !== "local"; +}; + export const computeBackupAgentName = ( localize: LocalizeFunc, agentId: string, @@ -229,6 +234,11 @@ export const computeBackupAgentName = ( return "This system"; } const [domain, name] = agentId.split("."); + + if (isNetworkMountAgent(agentId)) { + return name; + } + const domainName = domainToName(localize, domain); // If there are multiple agents for a domain, show the name @@ -242,7 +252,23 @@ export const computeBackupAgentName = ( export const compareAgents = (a: string, b: string) => { const isLocalA = isLocalAgent(a); const isLocalB = isLocalAgent(b); - return isLocalA === isLocalB ? a.localeCompare(b) : isLocalA ? -1 : 1; + const isNetworkMountAgentA = isNetworkMountAgent(a); + const isNetworkMountAgentB = isNetworkMountAgent(b); + + const getPriority = (isLocal: boolean, isNetworkMount: boolean) => { + if (isLocal) return 1; + if (isNetworkMount) return 2; + return 3; + }; + + const priorityA = getPriority(isLocalA, isNetworkMountAgentA); + const priorityB = getPriority(isLocalB, isNetworkMountAgentB); + + if (priorityA !== priorityB) { + return priorityA - priorityB; + } + + return a.localeCompare(b); }; export const generateEncryptionKey = () => { diff --git a/src/panels/config/backup/components/config/ha-backup-config-agents.ts b/src/panels/config/backup/components/config/ha-backup-config-agents.ts index f20aa8878be6..925b4f8f2de3 100644 --- a/src/panels/config/backup/components/config/ha-backup-config-agents.ts +++ b/src/panels/config/backup/components/config/ha-backup-config-agents.ts @@ -1,4 +1,4 @@ -import { mdiHarddisk } from "@mdi/js"; +import { mdiHarddisk, mdiNas } from "@mdi/js"; import type { PropertyValues } from "lit"; import { css, html, LitElement, nothing } from "lit"; import { customElement, property, state } from "lit/decorators"; @@ -14,6 +14,7 @@ import { computeBackupAgentName, fetchBackupAgentsInfo, isLocalAgent, + isNetworkMountAgent, } from "../../../../../data/backup"; import type { CloudStatus } from "../../../../../data/cloud"; import type { HomeAssistant } from "../../../../../types"; @@ -52,6 +53,9 @@ class HaBackupConfigAgents extends LitElement { if (agentId === CLOUD_AGENT) { return "It stores one backup. The oldest backups are deleted."; } + if (isNetworkMountAgent(agentId)) { + return "Network storage"; + } return ""; } @@ -75,20 +79,27 @@ class HaBackupConfigAgents extends LitElement { ` - : html` - - `} + : isNetworkMountAgent(agentId) + ? html` + + ` + : html` + + `}
${name}
${description ? html`
${description}
` diff --git a/src/panels/config/backup/components/ha-backup-agents-picker.ts b/src/panels/config/backup/components/ha-backup-agents-picker.ts index acf486dd6da5..7c032dce79e9 100644 --- a/src/panels/config/backup/components/ha-backup-agents-picker.ts +++ b/src/panels/config/backup/components/ha-backup-agents-picker.ts @@ -1,4 +1,4 @@ -import { mdiHarddisk } from "@mdi/js"; +import { mdiHarddisk, mdiNas } from "@mdi/js"; import { css, html, LitElement } from "lit"; import { customElement, property } from "lit/decorators"; import { classMap } from "lit/directives/class-map"; @@ -7,7 +7,11 @@ import { computeDomain } from "../../../../common/entity/compute_domain"; import "../../../../components/ha-checkbox"; import "../../../../components/ha-formfield"; import "../../../../components/ha-svg-icon"; -import { computeBackupAgentName, isLocalAgent } from "../../../../data/backup"; +import { + computeBackupAgentName, + isLocalAgent, + isNetworkMountAgent, +} from "../../../../data/backup"; import type { HomeAssistant } from "../../../../types"; import { brandsUrl } from "../../../../util/brands-url"; @@ -54,20 +58,22 @@ class HaBackupAgentsPicker extends LitElement { ? html` ` - : html` - - `} + : isNetworkMountAgent(agentId) + ? html` ` + : html` + + `} ${name} `; } + if (isNetworkMountAgent(agentId)) { + return html` + + `; + } const domain = computeDomain(agentId); return html` ` - : html` - - `} + : isNetworkMountAgent(agentId) + ? html` + + ` + : html` + + `}
${name}
Date: Mon, 23 Dec 2024 11:31:53 +0100 Subject: [PATCH 2/2] Add note to local backup location dialog --- .../backup/dialogs/dialog-local-backup-location.ts | 10 ++++++++++ src/translations/en.json | 1 + 2 files changed, 11 insertions(+) diff --git a/src/panels/config/backup/dialogs/dialog-local-backup-location.ts b/src/panels/config/backup/dialogs/dialog-local-backup-location.ts index 9ef762c8a3b7..3e171a54902d 100644 --- a/src/panels/config/backup/dialogs/dialog-local-backup-location.ts +++ b/src/panels/config/backup/dialogs/dialog-local-backup-location.ts @@ -5,6 +5,7 @@ import { fireEvent } from "../../../../common/dom/fire_event"; import "../../../../components/ha-button"; import { createCloseHeading } from "../../../../components/ha-dialog"; import "../../../../components/ha-form/ha-form"; +import "../../../../components/ha-alert"; import type { HaFormSchema, SchemaUnion, @@ -83,6 +84,11 @@ class LocalBackupLocationDialog extends LitElement { @value-changed=${this._valueChanged} dialogInitialFocus > + + ${this.hass.localize( + `ui.panel.config.backup.dialogs.local_backup_location.note` + )} +