diff --git a/src/data/config_entries.ts b/src/data/config_entries.ts index e83c0498d3..78cbe6105a 100644 --- a/src/data/config_entries.ts +++ b/src/data/config_entries.ts @@ -27,6 +27,12 @@ export type ConfigEntryMutableParams = Partial< > >; +export const ERROR_STATES: ConfigEntry["state"][] = [ + "migration_error", + "setup_error", + "setup_retry", +]; + export const getConfigEntries = (hass: HomeAssistant) => hass.callApi("GET", "config/config_entries/entry"); diff --git a/src/panels/config/integrations/ha-integration-card.ts b/src/panels/config/integrations/ha-integration-card.ts index 6549558047..4ac6414562 100644 --- a/src/panels/config/integrations/ha-integration-card.ts +++ b/src/panels/config/integrations/ha-integration-card.ts @@ -22,6 +22,7 @@ import { enableConfigEntry, reloadConfigEntry, updateConfigEntry, + ERROR_STATES, } from "../../../data/config_entries"; import type { DeviceRegistryEntry } from "../../../data/device_registry"; import type { EntityRegistryEntry } from "../../../data/entity_registry"; @@ -38,12 +39,6 @@ import type { HomeAssistant } from "../../../types"; import type { ConfigEntryExtended } from "./ha-config-integrations"; import "./ha-integration-header"; -const ERROR_STATES: ConfigEntry["state"][] = [ - "migration_error", - "setup_error", - "setup_retry", -]; - const integrationsWithPanel = { hassio: "/hassio/dashboard", mqtt: "/config/mqtt", diff --git a/src/panels/config/integrations/integration-panels/zwave_js/zwave_js-config-dashboard.ts b/src/panels/config/integrations/integration-panels/zwave_js/zwave_js-config-dashboard.ts index 3da2cff626..5903bdc044 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/zwave_js-config-dashboard.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/zwave_js-config-dashboard.ts @@ -1,6 +1,6 @@ import "@material/mwc-button/mwc-button"; import "@material/mwc-icon-button/mwc-icon-button"; -import { mdiCheckCircle, mdiCircle, mdiRefresh } from "@mdi/js"; +import { mdiAlertCircle, mdiCheckCircle, mdiCircle, mdiRefresh } from "@mdi/js"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; import { customElement, property, state } from "lit/decorators"; import { classMap } from "lit/directives/class-map"; @@ -17,6 +17,11 @@ import { ZWaveJSNetwork, ZWaveJSNode, } from "../../../../../data/zwave_js"; +import { + ConfigEntry, + getConfigEntries, + ERROR_STATES, +} from "../../../../../data/config_entries"; import { showAlertDialog, showConfirmationDialog, @@ -30,7 +35,6 @@ import { showZWaveJSAddNodeDialog } from "./show-dialog-zwave_js-add-node"; import { showZWaveJSHealNetworkDialog } from "./show-dialog-zwave_js-heal-network"; import { showZWaveJSRemoveNodeDialog } from "./show-dialog-zwave_js-remove-node"; import { configTabs } from "./zwave_js-config-router"; -import { getConfigEntries } from "../../../../../data/config_entries"; import { showOptionsFlowDialog } from "../../../../../dialogs/config-flow/show-dialog-options-flow"; @customElement("zwave_js-config-dashboard") @@ -45,6 +49,8 @@ class ZWaveJSConfigDashboard extends LitElement { @property() public configEntryId?: string; + @state() private _configEntry?: ConfigEntry; + @state() private _network?: ZWaveJSNetwork; @state() private _nodes?: ZWaveJSNode[]; @@ -62,6 +68,14 @@ class ZWaveJSConfigDashboard extends LitElement { } protected render(): TemplateResult { + if (!this._configEntry) { + return html``; + } + + if (ERROR_STATES.includes(this._configEntry.state)) { + return this._renderErrorScreen(); + } + return html` + ${this.hass.localize( + "ui.panel.config.integrations.config_entry.check_the_logs" + )} + `; + } + } + + return html` ${stateText + ? html` +
+ +

+ ${this._configEntry!.title}: ${this.hass.localize(...stateText)} +

+

${stateTextExtra}

+ + ${this.hass?.localize("ui.panel.error.go_back") || "go back"} + +
+ ` + : ""}`; + } + + private _handleBack(): void { + history.back(); + } + private async _fetchData() { if (!this.configEntryId) { return; } + const configEntries = await getConfigEntries(this.hass); + this._configEntry = configEntries.find( + (entry) => entry.entry_id === this.configEntryId! + ); + + if (ERROR_STATES.includes(this._configEntry!.state)) { + return; + } + const [network, dataCollectionStatus] = await Promise.all([ fetchNetworkStatus(this.hass!, this.configEntryId), fetchDataCollectionStatus(this.hass!, this.configEntryId), @@ -363,6 +450,27 @@ class ZWaveJSConfigDashboard extends LitElement { color: red; } + .error-message { + display: flex; + color: var(--primary-text-color); + height: calc(100% - var(--header-height)); + padding: 16px; + align-items: center; + justify-content: center; + flex-direction: column; + } + + .error-message h3 { + text-align: center; + font-weight: bold; + } + + .error-message ha-svg-icon { + color: var(--error-color); + width: 64px; + height: 64px; + } + .content { margin-top: 24px; }