mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Use name property when formatting backup location (#23916)
This commit is contained in:
parent
142faba04d
commit
85e4975206
@ -82,6 +82,7 @@ export interface BackupMutableConfig {
|
|||||||
|
|
||||||
export interface BackupAgent {
|
export interface BackupAgent {
|
||||||
agent_id: string;
|
agent_id: string;
|
||||||
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BackupContent {
|
export interface BackupContent {
|
||||||
@ -279,13 +280,18 @@ export const isNetworkMountAgent = (agentId: string) => {
|
|||||||
export const computeBackupAgentName = (
|
export const computeBackupAgentName = (
|
||||||
localize: LocalizeFunc,
|
localize: LocalizeFunc,
|
||||||
agentId: string,
|
agentId: string,
|
||||||
agentIds?: string[]
|
agents: BackupAgent[]
|
||||||
) => {
|
) => {
|
||||||
if (isLocalAgent(agentId)) {
|
if (isLocalAgent(agentId)) {
|
||||||
return localize("ui.panel.config.backup.agents.local_agent");
|
return localize("ui.panel.config.backup.agents.local_agent");
|
||||||
}
|
}
|
||||||
const [domain, name] = agentId.split(".");
|
|
||||||
|
|
||||||
|
const agent = agents.find((a) => a.agent_id === agentId);
|
||||||
|
|
||||||
|
const domain = agentId.split(".")[0];
|
||||||
|
const name = agent ? agent.name : agentId.split(".")[1];
|
||||||
|
|
||||||
|
// If it's a network mount agent, only show the name
|
||||||
if (isNetworkMountAgent(agentId)) {
|
if (isNetworkMountAgent(agentId)) {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
@ -293,9 +299,8 @@ export const computeBackupAgentName = (
|
|||||||
const domainName = domainToName(localize, domain);
|
const domainName = domainToName(localize, domain);
|
||||||
|
|
||||||
// If there are multiple agents for a domain, show the name
|
// If there are multiple agents for a domain, show the name
|
||||||
const showName = agentIds
|
const showName =
|
||||||
? agentIds.filter((a) => a.split(".")[0] === domain).length > 1
|
agents.filter((a) => a.agent_id.split(".")[0] === domain).length > 1;
|
||||||
: true;
|
|
||||||
|
|
||||||
return showName ? `${domainName}: ${name}` : domainName;
|
return showName ? `${domainName}: ${name}` : domainName;
|
||||||
};
|
};
|
||||||
|
@ -1,18 +1,17 @@
|
|||||||
import { mdiHarddisk, mdiNas } from "@mdi/js";
|
import { mdiHarddisk, mdiNas } from "@mdi/js";
|
||||||
import type { PropertyValues } from "lit";
|
|
||||||
import { css, html, LitElement, nothing } from "lit";
|
import { css, html, LitElement, nothing } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
|
import memoizeOne from "memoize-one";
|
||||||
import { fireEvent } from "../../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../../common/dom/fire_event";
|
||||||
import { computeDomain } from "../../../../../common/entity/compute_domain";
|
import { computeDomain } from "../../../../../common/entity/compute_domain";
|
||||||
import "../../../../../components/ha-md-list";
|
import "../../../../../components/ha-md-list";
|
||||||
import "../../../../../components/ha-md-list-item";
|
import "../../../../../components/ha-md-list-item";
|
||||||
import "../../../../../components/ha-svg-icon";
|
import "../../../../../components/ha-svg-icon";
|
||||||
import "../../../../../components/ha-switch";
|
import "../../../../../components/ha-switch";
|
||||||
|
import type { BackupAgent } from "../../../../../data/backup";
|
||||||
import {
|
import {
|
||||||
CLOUD_AGENT,
|
CLOUD_AGENT,
|
||||||
compareAgents,
|
|
||||||
computeBackupAgentName,
|
computeBackupAgentName,
|
||||||
fetchBackupAgentsInfo,
|
|
||||||
isLocalAgent,
|
isLocalAgent,
|
||||||
isNetworkMountAgent,
|
isNetworkMountAgent,
|
||||||
} from "../../../../../data/backup";
|
} from "../../../../../data/backup";
|
||||||
@ -28,22 +27,16 @@ class HaBackupConfigAgents extends LitElement {
|
|||||||
|
|
||||||
@property({ attribute: false }) public cloudStatus!: CloudStatus;
|
@property({ attribute: false }) public cloudStatus!: CloudStatus;
|
||||||
|
|
||||||
@state() private _agentIds: string[] = [];
|
@property({ attribute: false }) public agents: BackupAgent[] = [];
|
||||||
|
|
||||||
@state() private value?: string[];
|
@state() private value?: string[];
|
||||||
|
|
||||||
protected firstUpdated(_changedProperties: PropertyValues): void {
|
private _availableAgents = memoizeOne(
|
||||||
super.firstUpdated(_changedProperties);
|
(agents: BackupAgent[], cloudStatus: CloudStatus) =>
|
||||||
this._fetchAgents();
|
agents.filter(
|
||||||
}
|
(agent) => agent.agent_id !== CLOUD_AGENT || cloudStatus.logged_in
|
||||||
|
)
|
||||||
private async _fetchAgents() {
|
);
|
||||||
const { agents } = await fetchBackupAgentsInfo(this.hass);
|
|
||||||
this._agentIds = agents
|
|
||||||
.map((agent) => agent.agent_id)
|
|
||||||
.filter((id) => id !== CLOUD_AGENT || this.cloudStatus.logged_in)
|
|
||||||
.sort(compareAgents);
|
|
||||||
}
|
|
||||||
|
|
||||||
private get _value() {
|
private get _value() {
|
||||||
return this.value ?? DEFAULT_AGENTS;
|
return this.value ?? DEFAULT_AGENTS;
|
||||||
@ -69,16 +62,18 @@ class HaBackupConfigAgents extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
|
const agents = this._availableAgents(this.agents, this.cloudStatus);
|
||||||
return html`
|
return html`
|
||||||
${this._agentIds.length > 0
|
${agents.length > 0
|
||||||
? html`
|
? html`
|
||||||
<ha-md-list>
|
<ha-md-list>
|
||||||
${this._agentIds.map((agentId) => {
|
${agents.map((agent) => {
|
||||||
|
const agentId = agent.agent_id;
|
||||||
const domain = computeDomain(agentId);
|
const domain = computeDomain(agentId);
|
||||||
const name = computeBackupAgentName(
|
const name = computeBackupAgentName(
|
||||||
this.hass.localize,
|
this.hass.localize,
|
||||||
agentId,
|
agentId,
|
||||||
this._agentIds
|
this.agents
|
||||||
);
|
);
|
||||||
const description = this._description(agentId);
|
const description = this._description(agentId);
|
||||||
const noCloudSubscription =
|
const noCloudSubscription =
|
||||||
@ -130,9 +125,11 @@ class HaBackupConfigAgents extends LitElement {
|
|||||||
})}
|
})}
|
||||||
</ha-md-list>
|
</ha-md-list>
|
||||||
`
|
`
|
||||||
: html`<p>
|
: html`
|
||||||
${this.hass.localize("ui.panel.config.backup.agents.no_agents")}
|
<p>
|
||||||
</p>`}
|
${this.hass.localize("ui.panel.config.backup.agents.no_agents")}
|
||||||
|
</p>
|
||||||
|
`}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,9 +144,14 @@ class HaBackupConfigAgents extends LitElement {
|
|||||||
this.value = this._value.filter((agent) => agent !== agentId);
|
this.value = this._value.filter((agent) => agent !== agentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const availableAgents = this._availableAgents(
|
||||||
|
this.agents,
|
||||||
|
this.cloudStatus
|
||||||
|
);
|
||||||
|
|
||||||
// Ensure we don't have duplicates, agents exist in the list and cloud is logged in
|
// Ensure we don't have duplicates, agents exist in the list and cloud is logged in
|
||||||
this.value = [...new Set(this.value)]
|
this.value = [...new Set(this.value)]
|
||||||
.filter((agent) => this._agentIds.some((id) => id === agent))
|
.filter((id) => availableAgents.some((agent) => agent.agent_id === id))
|
||||||
.filter(
|
.filter(
|
||||||
(id) =>
|
(id) =>
|
||||||
id !== CLOUD_AGENT ||
|
id !== CLOUD_AGENT ||
|
||||||
|
@ -7,6 +7,7 @@ import { computeDomain } from "../../../../common/entity/compute_domain";
|
|||||||
import "../../../../components/ha-checkbox";
|
import "../../../../components/ha-checkbox";
|
||||||
import "../../../../components/ha-formfield";
|
import "../../../../components/ha-formfield";
|
||||||
import "../../../../components/ha-svg-icon";
|
import "../../../../components/ha-svg-icon";
|
||||||
|
import type { BackupAgent } from "../../../../data/backup";
|
||||||
import {
|
import {
|
||||||
computeBackupAgentName,
|
computeBackupAgentName,
|
||||||
isLocalAgent,
|
isLocalAgent,
|
||||||
@ -24,7 +25,7 @@ class HaBackupAgentsPicker extends LitElement {
|
|||||||
public disabled = false;
|
public disabled = false;
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
public agentIds!: string[];
|
public agents!: BackupAgent[];
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
public disabledAgentIds?: string[];
|
public disabledAgentIds?: string[];
|
||||||
@ -35,30 +36,30 @@ class HaBackupAgentsPicker extends LitElement {
|
|||||||
render() {
|
render() {
|
||||||
return html`
|
return html`
|
||||||
<div class="agents">
|
<div class="agents">
|
||||||
${this.agentIds.map((agent) => this._renderAgent(agent))}
|
${this.agents.map((agent) => this._renderAgent(agent))}
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _renderAgent(agentId: string) {
|
private _renderAgent(agent: BackupAgent) {
|
||||||
const domain = computeDomain(agentId);
|
const domain = computeDomain(agent.agent_id);
|
||||||
const name = computeBackupAgentName(
|
const name = computeBackupAgentName(
|
||||||
this.hass.localize,
|
this.hass.localize,
|
||||||
agentId,
|
agent.agent_id,
|
||||||
this.agentIds
|
this.agents
|
||||||
);
|
);
|
||||||
|
|
||||||
const disabled =
|
const disabled =
|
||||||
this.disabled || this.disabledAgentIds?.includes(agentId) || false;
|
this.disabled || this.disabledAgentIds?.includes(agent.agent_id) || false;
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-formfield>
|
<ha-formfield>
|
||||||
<span class="label ${classMap({ disabled })}" slot="label">
|
<span class="label ${classMap({ disabled })}" slot="label">
|
||||||
${isLocalAgent(agentId)
|
${isLocalAgent(agent.agent_id)
|
||||||
? html`
|
? html`
|
||||||
<ha-svg-icon .path=${mdiHarddisk} slot="start"> </ha-svg-icon>
|
<ha-svg-icon .path=${mdiHarddisk} slot="start"> </ha-svg-icon>
|
||||||
`
|
`
|
||||||
: isNetworkMountAgent(agentId)
|
: isNetworkMountAgent(agent.agent_id)
|
||||||
? html` <ha-svg-icon .path=${mdiNas} slot="start"></ha-svg-icon> `
|
? html` <ha-svg-icon .path=${mdiNas} slot="start"></ha-svg-icon> `
|
||||||
: html`
|
: html`
|
||||||
<img
|
<img
|
||||||
@ -77,8 +78,8 @@ class HaBackupAgentsPicker extends LitElement {
|
|||||||
${name}
|
${name}
|
||||||
</span>
|
</span>
|
||||||
<ha-checkbox
|
<ha-checkbox
|
||||||
.checked=${this.value.includes(agentId)}
|
.checked=${this.value.includes(agent.agent_id)}
|
||||||
.value=${agentId}
|
.value=${agent.agent_id}
|
||||||
.disabled=${disabled}
|
.disabled=${disabled}
|
||||||
@change=${this._checkboxChanged}
|
@change=${this._checkboxChanged}
|
||||||
></ha-checkbox>
|
></ha-checkbox>
|
||||||
|
@ -9,7 +9,7 @@ import "../../../../../components/ha-icon-next";
|
|||||||
import "../../../../../components/ha-md-list";
|
import "../../../../../components/ha-md-list";
|
||||||
import "../../../../../components/ha-md-list-item";
|
import "../../../../../components/ha-md-list-item";
|
||||||
import "../../../../../components/ha-svg-icon";
|
import "../../../../../components/ha-svg-icon";
|
||||||
import type { BackupConfig } from "../../../../../data/backup";
|
import type { BackupAgent, BackupConfig } from "../../../../../data/backup";
|
||||||
import {
|
import {
|
||||||
BackupScheduleRecurrence,
|
BackupScheduleRecurrence,
|
||||||
computeBackupAgentName,
|
computeBackupAgentName,
|
||||||
@ -25,6 +25,8 @@ class HaBackupBackupsSummary extends LitElement {
|
|||||||
|
|
||||||
@property({ attribute: false }) public config!: BackupConfig;
|
@property({ attribute: false }) public config!: BackupConfig;
|
||||||
|
|
||||||
|
@property({ attribute: false }) public agents!: BackupAgent[];
|
||||||
|
|
||||||
private _configure() {
|
private _configure() {
|
||||||
navigate("/config/backup/settings");
|
navigate("/config/backup/settings");
|
||||||
}
|
}
|
||||||
@ -160,7 +162,7 @@ class HaBackupBackupsSummary extends LitElement {
|
|||||||
const name = computeBackupAgentName(
|
const name = computeBackupAgentName(
|
||||||
this.hass.localize,
|
this.hass.localize,
|
||||||
offsiteLocations[0],
|
offsiteLocations[0],
|
||||||
offsiteLocations
|
this.agents
|
||||||
);
|
);
|
||||||
return this.hass.localize(
|
return this.hass.localize(
|
||||||
"ui.panel.config.backup.overview.settings.locations_one",
|
"ui.panel.config.backup.overview.settings.locations_one",
|
||||||
|
@ -18,6 +18,7 @@ import "../../../../components/ha-md-select";
|
|||||||
import "../../../../components/ha-md-select-option";
|
import "../../../../components/ha-md-select-option";
|
||||||
import "../../../../components/ha-textfield";
|
import "../../../../components/ha-textfield";
|
||||||
import type {
|
import type {
|
||||||
|
BackupAgent,
|
||||||
BackupConfig,
|
BackupConfig,
|
||||||
GenerateBackupParams,
|
GenerateBackupParams,
|
||||||
} from "../../../../data/backup";
|
} from "../../../../data/backup";
|
||||||
@ -64,7 +65,7 @@ class DialogGenerateBackup extends LitElement implements HassDialog {
|
|||||||
|
|
||||||
@state() private _step?: "data" | "sync";
|
@state() private _step?: "data" | "sync";
|
||||||
|
|
||||||
@state() private _agentIds: string[] = [];
|
@state() private _agents: BackupAgent[] = [];
|
||||||
|
|
||||||
@state() private _backupConfig?: BackupConfig;
|
@state() private _backupConfig?: BackupConfig;
|
||||||
|
|
||||||
@ -89,7 +90,7 @@ class DialogGenerateBackup extends LitElement implements HassDialog {
|
|||||||
}
|
}
|
||||||
this._step = undefined;
|
this._step = undefined;
|
||||||
this._formData = undefined;
|
this._formData = undefined;
|
||||||
this._agentIds = [];
|
this._agents = [];
|
||||||
this._backupConfig = undefined;
|
this._backupConfig = undefined;
|
||||||
this._params = undefined;
|
this._params = undefined;
|
||||||
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||||
@ -97,15 +98,14 @@ class DialogGenerateBackup extends LitElement implements HassDialog {
|
|||||||
|
|
||||||
private async _fetchAgents() {
|
private async _fetchAgents() {
|
||||||
const { agents } = await fetchBackupAgentsInfo(this.hass);
|
const { agents } = await fetchBackupAgentsInfo(this.hass);
|
||||||
this._agentIds = agents
|
this._agents = agents
|
||||||
.map((agent) => agent.agent_id)
|
|
||||||
.filter(
|
.filter(
|
||||||
(id) =>
|
(agent) =>
|
||||||
id !== CLOUD_AGENT ||
|
agent.agent_id !== CLOUD_AGENT ||
|
||||||
(this._params?.cloudStatus?.logged_in &&
|
(this._params?.cloudStatus?.logged_in &&
|
||||||
this._params?.cloudStatus?.active_subscription)
|
this._params?.cloudStatus?.active_subscription)
|
||||||
)
|
)
|
||||||
.sort(compareAgents);
|
.sort((a, b) => compareAgents(a.agent_id, b.agent_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _fetchBackupConfig() {
|
private async _fetchBackupConfig() {
|
||||||
@ -134,6 +134,10 @@ class DialogGenerateBackup extends LitElement implements HassDialog {
|
|||||||
this._step = STEPS[index + 1];
|
this._step = STEPS[index + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private get _allAgentIds() {
|
||||||
|
return this._agents.map((agent) => agent.agent_id);
|
||||||
|
}
|
||||||
|
|
||||||
protected willUpdate(changedProperties: PropertyValues): void {
|
protected willUpdate(changedProperties: PropertyValues): void {
|
||||||
super.willUpdate(changedProperties);
|
super.willUpdate(changedProperties);
|
||||||
|
|
||||||
@ -144,7 +148,7 @@ class DialogGenerateBackup extends LitElement implements HassDialog {
|
|||||||
// Remove disallowed agents from the list
|
// Remove disallowed agents from the list
|
||||||
const agentsIds =
|
const agentsIds =
|
||||||
this._formData.agents_mode === "all"
|
this._formData.agents_mode === "all"
|
||||||
? this._agentIds
|
? this._allAgentIds
|
||||||
: this._formData.agent_ids;
|
: this._formData.agent_ids;
|
||||||
|
|
||||||
const filteredAgents = agentsIds.filter(
|
const filteredAgents = agentsIds.filter(
|
||||||
@ -309,7 +313,7 @@ class DialogGenerateBackup extends LitElement implements HassDialog {
|
|||||||
<div slot="headline">
|
<div slot="headline">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.backup.dialogs.generate.sync.locations_options.all",
|
"ui.panel.config.backup.dialogs.generate.sync.locations_options.all",
|
||||||
{ count: this._agentIds.length }
|
{ count: this._allAgentIds.length }
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</ha-md-select-option>
|
</ha-md-select-option>
|
||||||
@ -350,7 +354,7 @@ class DialogGenerateBackup extends LitElement implements HassDialog {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.value=${this._formData.agent_ids}
|
.value=${this._formData.agent_ids}
|
||||||
@value-changed=${this._agentsChanged}
|
@value-changed=${this._agentsChanged}
|
||||||
.agentIds=${this._agentIds}
|
.agents=${this._agents}
|
||||||
.disabledAgentIds=${disabledAgentIds}
|
.disabledAgentIds=${disabledAgentIds}
|
||||||
></ha-backup-agents-picker>
|
></ha-backup-agents-picker>
|
||||||
</ha-expansion-panel>
|
</ha-expansion-panel>
|
||||||
@ -385,7 +389,7 @@ class DialogGenerateBackup extends LitElement implements HassDialog {
|
|||||||
if (!this._formData) {
|
if (!this._formData) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
const allAgents = this._agentIds;
|
const allAgents = this._allAgentIds;
|
||||||
return !this._formData.data.include_homeassistant
|
return !this._formData.data.include_homeassistant
|
||||||
? DISALLOWED_AGENTS_NO_HA.filter((agentId) => allAgents.includes(agentId))
|
? DISALLOWED_AGENTS_NO_HA.filter((agentId) => allAgents.includes(agentId))
|
||||||
: [];
|
: [];
|
||||||
@ -403,7 +407,7 @@ class DialogGenerateBackup extends LitElement implements HassDialog {
|
|||||||
const params: GenerateBackupParams = {
|
const params: GenerateBackupParams = {
|
||||||
name,
|
name,
|
||||||
password,
|
password,
|
||||||
agent_ids: agents_mode === "all" ? this._agentIds : agent_ids,
|
agent_ids: agents_mode === "all" ? this._allAgentIds : agent_ids,
|
||||||
// We always include homeassistant if we include database
|
// We always include homeassistant if we include database
|
||||||
include_homeassistant:
|
include_homeassistant:
|
||||||
data.include_homeassistant || data.include_database,
|
data.include_homeassistant || data.include_database,
|
||||||
|
@ -33,7 +33,11 @@ import "../../../components/ha-icon-next";
|
|||||||
import "../../../components/ha-icon-overflow-menu";
|
import "../../../components/ha-icon-overflow-menu";
|
||||||
import "../../../components/ha-list-item";
|
import "../../../components/ha-list-item";
|
||||||
import "../../../components/ha-svg-icon";
|
import "../../../components/ha-svg-icon";
|
||||||
import type { BackupConfig, BackupContent } from "../../../data/backup";
|
import type {
|
||||||
|
BackupAgent,
|
||||||
|
BackupConfig,
|
||||||
|
BackupContent,
|
||||||
|
} from "../../../data/backup";
|
||||||
import {
|
import {
|
||||||
computeBackupAgentName,
|
computeBackupAgentName,
|
||||||
deleteBackup,
|
deleteBackup,
|
||||||
@ -86,6 +90,8 @@ class HaConfigBackupBackups extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
@property({ attribute: false }) public config?: BackupConfig;
|
@property({ attribute: false }) public config?: BackupConfig;
|
||||||
|
|
||||||
|
@property({ attribute: false }) public agents: BackupAgent[] = [];
|
||||||
|
|
||||||
@state() private _selected: string[] = [];
|
@state() private _selected: string[] = [];
|
||||||
|
|
||||||
@storage({
|
@storage({
|
||||||
@ -169,7 +175,7 @@ class HaConfigBackupBackups extends SubscribeMixin(LitElement) {
|
|||||||
const name = computeBackupAgentName(
|
const name = computeBackupAgentName(
|
||||||
this.hass.localize,
|
this.hass.localize,
|
||||||
agentId,
|
agentId,
|
||||||
backup.agent_ids
|
this.agents
|
||||||
);
|
);
|
||||||
if (isLocalAgent(agentId)) {
|
if (isLocalAgent(agentId)) {
|
||||||
return html`
|
return html`
|
||||||
|
@ -21,6 +21,7 @@ import "../../../components/ha-list-item";
|
|||||||
import "../../../components/ha-md-list";
|
import "../../../components/ha-md-list";
|
||||||
import "../../../components/ha-md-list-item";
|
import "../../../components/ha-md-list-item";
|
||||||
import type {
|
import type {
|
||||||
|
BackupAgent,
|
||||||
BackupConfig,
|
BackupConfig,
|
||||||
BackupContentExtended,
|
BackupContentExtended,
|
||||||
BackupData,
|
BackupData,
|
||||||
@ -70,6 +71,8 @@ class HaConfigBackupDetails extends LitElement {
|
|||||||
|
|
||||||
@property({ attribute: false }) public config?: BackupConfig;
|
@property({ attribute: false }) public config?: BackupConfig;
|
||||||
|
|
||||||
|
@property({ attribute: false }) public agents: BackupAgent[] = [];
|
||||||
|
|
||||||
@state() private _backup?: BackupContentExtended | null;
|
@state() private _backup?: BackupContentExtended | null;
|
||||||
|
|
||||||
@state() private _agents: Agent[] = [];
|
@state() private _agents: Agent[] = [];
|
||||||
@ -232,7 +235,7 @@ class HaConfigBackupDetails extends LitElement {
|
|||||||
const name = computeBackupAgentName(
|
const name = computeBackupAgentName(
|
||||||
this.hass.localize,
|
this.hass.localize,
|
||||||
agentId,
|
agentId,
|
||||||
this._backup!.agent_ids
|
this.agents
|
||||||
);
|
);
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
|
@ -13,11 +13,14 @@ import "../../../components/ha-icon-next";
|
|||||||
import "../../../components/ha-icon-overflow-menu";
|
import "../../../components/ha-icon-overflow-menu";
|
||||||
import "../../../components/ha-list-item";
|
import "../../../components/ha-list-item";
|
||||||
import "../../../components/ha-svg-icon";
|
import "../../../components/ha-svg-icon";
|
||||||
|
import type {
|
||||||
|
BackupAgent,
|
||||||
|
BackupConfig,
|
||||||
|
BackupContent,
|
||||||
|
} from "../../../data/backup";
|
||||||
import {
|
import {
|
||||||
generateBackup,
|
generateBackup,
|
||||||
generateBackupWithAutomaticSettings,
|
generateBackupWithAutomaticSettings,
|
||||||
type BackupConfig,
|
|
||||||
type BackupContent,
|
|
||||||
} from "../../../data/backup";
|
} from "../../../data/backup";
|
||||||
import type { ManagerStateEvent } from "../../../data/backup_manager";
|
import type { ManagerStateEvent } from "../../../data/backup_manager";
|
||||||
import type { CloudStatus } from "../../../data/cloud";
|
import type { CloudStatus } from "../../../data/cloud";
|
||||||
@ -53,6 +56,8 @@ class HaConfigBackupOverview extends LitElement {
|
|||||||
|
|
||||||
@property({ attribute: false }) public config?: BackupConfig;
|
@property({ attribute: false }) public config?: BackupConfig;
|
||||||
|
|
||||||
|
@property({ attribute: false }) public agents: BackupAgent[] = [];
|
||||||
|
|
||||||
private async _uploadBackup(ev) {
|
private async _uploadBackup(ev) {
|
||||||
if (!shouldHandleRequestSelectedEvent(ev)) {
|
if (!shouldHandleRequestSelectedEvent(ev)) {
|
||||||
return;
|
return;
|
||||||
@ -184,6 +189,7 @@ class HaConfigBackupOverview extends LitElement {
|
|||||||
<ha-backup-overview-settings
|
<ha-backup-overview-settings
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.config=${this.config!}
|
.config=${this.config!}
|
||||||
|
.agents=${this.agents}
|
||||||
></ha-backup-overview-settings>
|
></ha-backup-overview-settings>
|
||||||
`
|
`
|
||||||
: nothing}
|
: nothing}
|
||||||
|
@ -16,7 +16,7 @@ import "../../../components/ha-list-item";
|
|||||||
import "../../../components/ha-alert";
|
import "../../../components/ha-alert";
|
||||||
import "../../../components/ha-password-field";
|
import "../../../components/ha-password-field";
|
||||||
import "../../../components/ha-svg-icon";
|
import "../../../components/ha-svg-icon";
|
||||||
import type { BackupConfig } from "../../../data/backup";
|
import type { BackupAgent, BackupConfig } from "../../../data/backup";
|
||||||
import { updateBackupConfig } from "../../../data/backup";
|
import { updateBackupConfig } from "../../../data/backup";
|
||||||
import type { CloudStatus } from "../../../data/cloud";
|
import type { CloudStatus } from "../../../data/cloud";
|
||||||
import "../../../layouts/hass-subpage";
|
import "../../../layouts/hass-subpage";
|
||||||
@ -39,6 +39,8 @@ class HaConfigBackupSettings extends LitElement {
|
|||||||
|
|
||||||
@property({ attribute: false }) public config?: BackupConfig;
|
@property({ attribute: false }) public config?: BackupConfig;
|
||||||
|
|
||||||
|
@property({ attribute: false }) public agents: BackupAgent[] = [];
|
||||||
|
|
||||||
@state() private _config?: BackupConfig;
|
@state() private _config?: BackupConfig;
|
||||||
|
|
||||||
protected willUpdate(changedProperties: PropertyValues): void {
|
protected willUpdate(changedProperties: PropertyValues): void {
|
||||||
@ -178,6 +180,7 @@ class HaConfigBackupSettings extends LitElement {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.value=${this._config.create_backup.agent_ids}
|
.value=${this._config.create_backup.agent_ids}
|
||||||
.cloudStatus=${this.cloudStatus}
|
.cloudStatus=${this.cloudStatus}
|
||||||
|
.agents=${this.agents}
|
||||||
@value-changed=${this._agentsConfigChanged}
|
@value-changed=${this._agentsConfigChanged}
|
||||||
></ha-backup-config-agents>
|
></ha-backup-config-agents>
|
||||||
${!this._config.create_backup.agent_ids.length
|
${!this._config.create_backup.agent_ids.length
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
|
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||||
import type { PropertyValues } from "lit";
|
import type { PropertyValues } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import type { BackupConfig, BackupContent } from "../../../data/backup";
|
import type {
|
||||||
|
BackupAgent,
|
||||||
|
BackupConfig,
|
||||||
|
BackupContent,
|
||||||
|
} from "../../../data/backup";
|
||||||
import {
|
import {
|
||||||
compareAgents,
|
compareAgents,
|
||||||
|
fetchBackupAgentsInfo,
|
||||||
fetchBackupConfig,
|
fetchBackupConfig,
|
||||||
fetchBackupInfo,
|
fetchBackupInfo,
|
||||||
} from "../../../data/backup";
|
} from "../../../data/backup";
|
||||||
@ -41,6 +46,8 @@ class HaConfigBackup extends SubscribeMixin(HassRouterPage) {
|
|||||||
|
|
||||||
@state() private _backups: BackupContent[] = [];
|
@state() private _backups: BackupContent[] = [];
|
||||||
|
|
||||||
|
@state() private _agents: BackupAgent[] = [];
|
||||||
|
|
||||||
@state() private _fetching = false;
|
@state() private _fetching = false;
|
||||||
|
|
||||||
@state() private _config?: BackupConfig;
|
@state() private _config?: BackupConfig;
|
||||||
@ -54,15 +61,20 @@ class HaConfigBackup extends SubscribeMixin(HassRouterPage) {
|
|||||||
this.addEventListener("ha-refresh-backup-config", () => {
|
this.addEventListener("ha-refresh-backup-config", () => {
|
||||||
this._fetchBackupConfig();
|
this._fetchBackupConfig();
|
||||||
});
|
});
|
||||||
|
this.addEventListener("ha-refresh-backup-agents", () => {
|
||||||
|
this._fetchBackupAgents();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _fetchAll() {
|
private _fetchAll() {
|
||||||
this._fetching = true;
|
this._fetching = true;
|
||||||
Promise.all([this._fetchBackupInfo(), this._fetchBackupConfig()]).finally(
|
Promise.all([
|
||||||
() => {
|
this._fetchBackupInfo(),
|
||||||
this._fetching = false;
|
this._fetchBackupConfig(),
|
||||||
}
|
this._fetchBackupAgents(),
|
||||||
);
|
]).finally(() => {
|
||||||
|
this._fetching = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public connectedCallback() {
|
public connectedCallback() {
|
||||||
@ -70,6 +82,7 @@ class HaConfigBackup extends SubscribeMixin(HassRouterPage) {
|
|||||||
if (this.hasUpdated) {
|
if (this.hasUpdated) {
|
||||||
this._fetchBackupInfo();
|
this._fetchBackupInfo();
|
||||||
this._fetchBackupConfig();
|
this._fetchBackupConfig();
|
||||||
|
this._fetchBackupAgents();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,6 +100,11 @@ class HaConfigBackup extends SubscribeMixin(HassRouterPage) {
|
|||||||
this._config = config;
|
this._config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _fetchBackupAgents() {
|
||||||
|
const { agents } = await fetchBackupAgentsInfo(this.hass);
|
||||||
|
this._agents = agents.sort((a, b) => compareAgents(a.agent_id, b.agent_id));
|
||||||
|
}
|
||||||
|
|
||||||
protected routerOptions: RouterOptions = {
|
protected routerOptions: RouterOptions = {
|
||||||
defaultPage: "overview",
|
defaultPage: "overview",
|
||||||
routes: {
|
routes: {
|
||||||
@ -117,6 +135,7 @@ class HaConfigBackup extends SubscribeMixin(HassRouterPage) {
|
|||||||
pageEl.manager = this._manager;
|
pageEl.manager = this._manager;
|
||||||
pageEl.backups = this._backups;
|
pageEl.backups = this._backups;
|
||||||
pageEl.config = this._config;
|
pageEl.config = this._config;
|
||||||
|
pageEl.agents = this._agents;
|
||||||
pageEl.fetching = this._fetching;
|
pageEl.fetching = this._fetching;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user