diff --git a/src/data/recorder.ts b/src/data/recorder.ts index dcfe19480b..de173e9720 100644 --- a/src/data/recorder.ts +++ b/src/data/recorder.ts @@ -5,6 +5,7 @@ import type { HomeAssistant } from "../types"; export interface RecorderInfo { backlog: number | null; + db_in_default_location: boolean; max_backlog: number; migration_in_progress: boolean; migration_is_live: boolean; diff --git a/src/panels/config/backup/components/config/ha-backup-config-data.ts b/src/panels/config/backup/components/config/ha-backup-config-data.ts index 8e12093819..34b41843dc 100644 --- a/src/panels/config/backup/components/config/ha-backup-config-data.ts +++ b/src/panels/config/backup/components/config/ha-backup-config-data.ts @@ -24,6 +24,7 @@ import { fetchHassioAddonsInfo } from "../../../../../data/hassio/addon"; import type { HomeAssistant } from "../../../../../types"; import "../ha-backup-addons-picker"; import type { BackupAddonItem } from "../ha-backup-addons-picker"; +import { getRecorderInfo } from "../../../../../data/recorder"; export interface FormData { homeassistant: boolean; @@ -75,8 +76,11 @@ class HaBackupConfigData extends LitElement { @state() private _showAddons = false; + @state() private _showDbOption = true; + protected firstUpdated(changedProperties: PropertyValues): void { super.firstUpdated(changedProperties); + this._checkDbOption(); if (isComponentLoaded(this.hass, "hassio")) { this._fetchAddons(); } @@ -98,6 +102,18 @@ class HaBackupConfigData extends LitElement { fireEvent(this, "backup-addons-fetched"); } + private async _checkDbOption() { + if (isComponentLoaded(this.hass, "recorder")) { + const info = await getRecorderInfo(this.hass.connection); + this._showDbOption = info.db_in_default_location; + if (!this._showDbOption && this.value?.include_database) { + this.value.include_database = false; + } + } else { + this._showDbOption = false; + } + } + private _hasLocalAddons(addons: BackupAddonItem[]): boolean { return addons.some((addon) => addon.slug === "local"); } @@ -179,24 +195,25 @@ class HaBackupConfigData extends LitElement { > - - - - ${this.hass.localize("ui.panel.config.backup.data.history")} - - - ${this.hass.localize( - "ui.panel.config.backup.data.history_description" - )} - - - - + ${this._showDbOption + ? html` + + + ${this.hass.localize("ui.panel.config.backup.data.history")} + + + ${this.hass.localize( + "ui.panel.config.backup.data.history_description" + )} + + + ` + : nothing} ${isHassio ? html` diff --git a/src/panels/config/backup/components/overview/ha-backup-overview-settings.ts b/src/panels/config/backup/components/overview/ha-backup-overview-settings.ts index e083c58712..4fd90b7048 100644 --- a/src/panels/config/backup/components/overview/ha-backup-overview-settings.ts +++ b/src/panels/config/backup/components/overview/ha-backup-overview-settings.ts @@ -1,7 +1,7 @@ import { mdiCalendar, mdiDatabase, mdiPuzzle, mdiUpload } from "@mdi/js"; -import type { CSSResultGroup } from "lit"; +import type { CSSResultGroup, PropertyValues } from "lit"; import { css, html, LitElement, nothing } from "lit"; -import { customElement, property } from "lit/decorators"; +import { customElement, property, state } from "lit/decorators"; import { navigate } from "../../../../../common/navigate"; import "../../../../../components/ha-button"; import "../../../../../components/ha-card"; @@ -18,6 +18,8 @@ import { } from "../../../../../data/backup"; import { haStyle } from "../../../../../resources/styles"; import type { HomeAssistant } from "../../../../../types"; +import { isComponentLoaded } from "../../../../../common/config/is_component_loaded"; +import { getRecorderInfo } from "../../../../../data/recorder"; @customElement("ha-backup-overview-settings") class HaBackupBackupsSummary extends LitElement { @@ -27,10 +29,26 @@ class HaBackupBackupsSummary extends LitElement { @property({ attribute: false }) public agents!: BackupAgent[]; + @state() private _showDbOption = true; + + protected firstUpdated(changedProperties: PropertyValues): void { + super.firstUpdated(changedProperties); + this._checkDbOption(); + } + private _configure() { navigate("/config/backup/settings"); } + private async _checkDbOption() { + if (isComponentLoaded(this.hass, "recorder")) { + const info = await getRecorderInfo(this.hass.connection); + this._showDbOption = info.db_in_default_location; + } else { + this._showDbOption = false; + } + } + private _scheduleDescription(config: BackupConfig): string { const { copies, days } = config.retention; const { recurrence } = config.schedule; @@ -214,7 +232,8 @@ class HaBackupBackupsSummary extends LitElement { - ${this.config.create_backup.include_database + ${this._showDbOption && + this.config.create_backup.include_database ? this.hass.localize( "ui.panel.config.backup.overview.settings.data_settings_history" )