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

Add icon and description for network mount locations #23390

Merged
merged 2 commits into from
Dec 23, 2024
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
28 changes: 27 additions & 1 deletion src/data/backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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 = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -14,6 +14,7 @@ import {
computeBackupAgentName,
fetchBackupAgentsInfo,
isLocalAgent,
isNetworkMountAgent,
} from "../../../../../data/backup";
import type { CloudStatus } from "../../../../../data/cloud";
import type { HomeAssistant } from "../../../../../types";
Expand Down Expand Up @@ -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 "";
}

Expand All @@ -75,20 +79,27 @@ class HaBackupConfigAgents extends LitElement {
<ha-svg-icon .path=${mdiHarddisk} slot="start">
</ha-svg-icon>
`
: html`
<img
.src=${brandsUrl({
domain,
type: "icon",
useFallback: true,
darkOptimized: this.hass.themes?.darkMode,
})}
crossorigin="anonymous"
referrerpolicy="no-referrer"
alt=""
slot="start"
/>
`}
: isNetworkMountAgent(agentId)
? html`
<ha-svg-icon
.path=${mdiNas}
slot="start"
></ha-svg-icon>
`
: html`
<img
.src=${brandsUrl({
domain,
type: "icon",
useFallback: true,
darkOptimized: this.hass.themes?.darkMode,
})}
crossorigin="anonymous"
referrerpolicy="no-referrer"
alt=""
slot="start"
/>
`}
<div slot="headline">${name}</div>
${description
? html`<div slot="supporting-text">${description}</div>`
Expand Down
38 changes: 22 additions & 16 deletions src/panels/config/backup/components/ha-backup-agents-picker.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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";

Expand Down Expand Up @@ -54,20 +58,22 @@ class HaBackupAgentsPicker extends LitElement {
? html`
<ha-svg-icon .path=${mdiHarddisk} slot="start"> </ha-svg-icon>
`
: html`
<img
.src=${brandsUrl({
domain,
type: "icon",
useFallback: true,
darkOptimized: this.hass.themes?.darkMode,
})}
crossorigin="anonymous"
referrerpolicy="no-referrer"
alt=""
slot="start"
/>
`}
: isNetworkMountAgent(agentId)
? html` <ha-svg-icon .path=${mdiNas} slot="start"></ha-svg-icon> `
: html`
<img
.src=${brandsUrl({
domain,
type: "icon",
useFallback: true,
darkOptimized: this.hass.themes?.darkMode,
})}
crossorigin="anonymous"
referrerpolicy="no-referrer"
alt=""
slot="start"
/>
`}
${name}
</span>
<ha-checkbox
Expand Down
10 changes: 10 additions & 0 deletions src/panels/config/backup/dialogs/dialog-local-backup-location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -83,6 +84,11 @@ class LocalBackupLocationDialog extends LitElement {
@value-changed=${this._valueChanged}
dialogInitialFocus
></ha-form>
<ha-alert alert-type="info">
${this.hass.localize(
`ui.panel.config.backup.dialogs.local_backup_location.note`
)}
</ha-alert>
<ha-button
slot="secondaryAction"
@click=${this.closeDialog}
Expand Down Expand Up @@ -139,6 +145,10 @@ class LocalBackupLocationDialog extends LitElement {
ha-dialog {
--mdc-dialog-max-width: 500px;
}
ha-form {
display: block;
margin-bottom: 16px;
}
`,
];
}
Expand Down
11 changes: 11 additions & 0 deletions src/panels/config/backup/ha-config-backup-backups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
mdiDotsVertical,
mdiDownload,
mdiHarddisk,
mdiNas,
mdiPlus,
mdiUpload,
} from "@mdi/js";
Expand Down Expand Up @@ -44,6 +45,7 @@ import {
getBackupDownloadUrl,
getPreferredAgentForDownload,
isLocalAgent,
isNetworkMountAgent,
} from "../../../data/backup";
import type { ManagerStateEvent } from "../../../data/backup_manager";
import type { CloudStatus } from "../../../data/cloud";
Expand Down Expand Up @@ -184,6 +186,15 @@ class HaConfigBackupBackups extends SubscribeMixin(LitElement) {
></ha-svg-icon>
`;
}
if (isNetworkMountAgent(agentId)) {
return html`
<ha-svg-icon
.path=${mdiNas}
title=${name}
slot="graphic"
></ha-svg-icon>
`;
}
const domain = computeDomain(agentId);
return html`
<img
Expand Down
46 changes: 30 additions & 16 deletions src/panels/config/backup/ha-config-backup-details.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import type { ActionDetail } from "@material/mwc-list";
import { mdiDelete, mdiDotsVertical, mdiDownload, mdiHarddisk } from "@mdi/js";
import {
mdiDelete,
mdiDotsVertical,
mdiDownload,
mdiHarddisk,
mdiNas,
} from "@mdi/js";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import { formatDateTime } from "../../../common/datetime/format_date_time";
Expand All @@ -24,6 +30,7 @@ import {
getBackupDownloadUrl,
getPreferredAgentForDownload,
isLocalAgent,
isNetworkMountAgent,
} from "../../../data/backup";
import type { HassioAddonInfo } from "../../../data/hassio/addon";
import "../../../layouts/hass-subpage";
Expand Down Expand Up @@ -184,21 +191,28 @@ class HaConfigBackupDetails extends LitElement {
>
</ha-svg-icon>
`
: html`
<img
.src=${brandsUrl({
domain,
type: "icon",
useFallback: true,
darkOptimized:
this.hass.themes?.darkMode,
})}
crossorigin="anonymous"
referrerpolicy="no-referrer"
alt=""
slot="start"
/>
`}
: isNetworkMountAgent(agentId)
? html`
<ha-svg-icon
.path=${mdiNas}
slot="start"
></ha-svg-icon>
`
: html`
<img
.src=${brandsUrl({
domain,
type: "icon",
useFallback: true,
darkOptimized:
this.hass.themes?.darkMode,
})}
crossorigin="anonymous"
referrerpolicy="no-referrer"
alt=""
slot="start"
/>
`}
<div slot="headline">${name}</div>
<div slot="supporting-text">
<span
Expand Down
1 change: 1 addition & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2214,6 +2214,7 @@
"local_backup_location": {
"title": "Change local backup location",
"description": "Change the default location where local backups are stored on your Home Assistant instance.",
"note": "This location will be used when you create a backup using the supervisor actions in an automation for example.",
"options": {
"default_backup_mount": {
"name": "Default location"
Expand Down
Loading