diff --git a/src/panels/config/dashboard/ha-config-dashboard.ts b/src/panels/config/dashboard/ha-config-dashboard.ts index 63b652a22b..5b54bc8850 100644 --- a/src/panels/config/dashboard/ha-config-dashboard.ts +++ b/src/panels/config/dashboard/ha-config-dashboard.ts @@ -1,3 +1,4 @@ +import { memoize } from "@fullcalendar/core"; import "@material/mwc-list/mwc-list"; import "@material/mwc-list/mwc-list-item"; import { mdiChevronRight } from "@mdi/js"; @@ -37,7 +38,13 @@ import { subscribeEntityRegistry, } from "../../../data/entity_registry"; import { domainToName } from "../../../data/integration"; +import { + fetchDashboards, + LovelaceDashboard, + LovelacePanelConfig, +} from "../../../data/lovelace"; import { fetchPersons, Person } from "../../../data/person"; +import { fetchTags, Tag } from "../../../data/tag"; import "../../../layouts/ha-app-layout"; import { haStyle } from "../../../resources/styles"; import { HomeAssistant } from "../../../types"; @@ -69,6 +76,10 @@ class HaConfigDashboard extends LitElement { @internalProperty() private _deviceRegistryEntries: DeviceRegistryEntry[] = []; + @internalProperty() private _tags: Tag[] = []; + + @internalProperty() private _dashboards: LovelaceDashboard[] = []; + protected render(): TemplateResult { return html` @@ -112,6 +123,7 @@ class HaConfigDashboard extends LitElement { Remote UI Connected @@ -120,6 +132,7 @@ class HaConfigDashboard extends LitElement { Google Assistant Enabled @@ -128,6 +141,7 @@ class HaConfigDashboard extends LitElement { Amazon Alexa Disabled @@ -136,6 +150,7 @@ class HaConfigDashboard extends LitElement { Webhooks 3 active @@ -151,6 +166,7 @@ class HaConfigDashboard extends LitElement { Location Settings Unit system, timezone, etc @@ -159,6 +175,7 @@ class HaConfigDashboard extends LitElement { Server Control Stop and Start Home Assistant @@ -167,6 +184,7 @@ class HaConfigDashboard extends LitElement { Logs Server Logs @@ -175,6 +193,7 @@ class HaConfigDashboard extends LitElement { Add-ons Manage Addons @@ -183,6 +202,7 @@ class HaConfigDashboard extends LitElement { About Info about the server @@ -277,6 +297,7 @@ class HaConfigDashboard extends LitElement { @@ -290,16 +311,16 @@ class HaConfigDashboard extends LitElement { ${this._getScripts(this.hass.states).map( - (automation) => html` + (script) => html` - ${automation.attributes.friendly_name} + ${script.attributes.friendly_name} ${this.hass.localize( "ui.card.automation.last_triggered" )}: - ${automation.attributes.last_triggered + ${script.attributes.last_triggered ? formatDateTime( - new Date(automation.attributes.last_triggered), + new Date(script.attributes.last_triggered), this.hass.language ) : this.hass.localize( @@ -308,6 +329,7 @@ class HaConfigDashboard extends LitElement { @@ -321,16 +343,16 @@ class HaConfigDashboard extends LitElement { ${this._getScenes(this.hass.states).map( - (automation) => html` + (scene) => html` - ${automation.attributes.friendly_name} + ${scene.attributes.friendly_name} ${this.hass.localize( "ui.card.automation.last_triggered" )}: - ${automation.attributes.last_triggered + ${scene.attributes.last_triggered ? formatDateTime( - new Date(automation.attributes.last_triggered), + new Date(scene.attributes.last_triggered), this.hass.language ) : this.hass.localize( @@ -339,6 +361,7 @@ class HaConfigDashboard extends LitElement { @@ -352,16 +375,16 @@ class HaConfigDashboard extends LitElement { ${this._getHelpers(this.hass.states).map( - (automation) => html` + (helper) => html` - ${automation.attributes.friendly_name} + ${helper.attributes.friendly_name} ${this.hass.localize( "ui.card.automation.last_triggered" )}: - ${automation.attributes.last_triggered + ${helper.attributes.last_triggered ? formatDateTime( - new Date(automation.attributes.last_triggered), + new Date(helper.attributes.last_triggered), this.hass.language ) : this.hass.localize( @@ -370,6 +393,7 @@ class HaConfigDashboard extends LitElement { @@ -380,6 +404,73 @@ class HaConfigDashboard extends LitElement { Manage Helpers + + + ${this._tags.map( + (tag) => html` + + ${tag.name} + ${this.hass.localize( + "ui.panel.config.tags.headers.last_scanned" + )}: + ${tag.last_scanned + ? html` + + ` + : this.hass.localize( + "ui.panel.config.tags.never_scanned" + )} + + + + ` + )} + + + + + + ${this._getDasboards(this._dashboards).map( + (dashboard) => html` + + + ${dashboard.title} + + ${this.hass.localize( + `ui.panel.config.lovelace.dashboards.conf_mode.${dashboard.mode}` + )}${dashboard.filename + ? html` - ${dashboard.filename} ` + : ""} + + + + ` + )} + + + @@ -390,6 +481,8 @@ class HaConfigDashboard extends LitElement { super.firstUpdated(changedProps); this._fetchPersonData(); this._fetchIntegrationData(); + this._fetchTags(); + this._fetchDasboards(); subscribeEntityRegistry(this.hass.connection, (entries) => { this._entityRegistryEntries = entries; }); @@ -496,6 +589,40 @@ class HaConfigDashboard extends LitElement { } ); + private async _fetchTags() { + this._tags = await fetchTags(this.hass); + } + + private async _fetchDasboards() { + this._dashboards = await fetchDashboards(this.hass); + } + + private _getDasboards = memoize((dashboards: LovelaceDashboard[]) => { + const defaultMode = (this.hass.panels?.lovelace + ?.config as LovelacePanelConfig).mode; + const defaultUrlPath = this.hass.defaultPanel; + const isDefault = defaultUrlPath === "lovelace"; + return [ + { + icon: "hass:view-dashboard", + title: this.hass.localize("panel.states"), + default: isDefault, + sidebar: isDefault, + require_admin: false, + url_path: "lovelace", + mode: defaultMode, + filename: defaultMode === "yaml" ? "ui-lovelace.yaml" : "", + }, + ...dashboards.map((dashboard) => { + return { + filename: "", + ...dashboard, + default: defaultUrlPath === dashboard.url_path, + }; + }), + ].slice(0, 2); + }); + static get styles(): CSSResultArray { return [ haStyle, @@ -606,6 +733,21 @@ class HaConfigDashboard extends LitElement { grid-area: Scene; } + #HelperCard { + display: flex; + flex-direction: column; + } + + #TagsCard { + display: flex; + flex-direction: column; + } + + #LovelaceCard { + display: flex; + flex-direction: column; + } + .footer { width: 100%; min-height: 35px; @@ -617,6 +759,10 @@ class HaConfigDashboard extends LitElement { font-size: 14px; line-height: 1.2; } + + .meta-icon { + color: var(--secondary-text-color); + } `, ]; }