diff --git a/src/data/repairs.ts b/src/data/repairs.ts index b70b115c60..b7264379a5 100644 --- a/src/data/repairs.ts +++ b/src/data/repairs.ts @@ -6,7 +6,7 @@ export interface RepairsIssue { issue_id: string; active: boolean; is_fixable: boolean; - severity?: "error" | "warning" | "critical"; + severity: "error" | "warning" | "critical"; breaks_in_ha_version?: string; ignored: boolean; created: string; @@ -16,6 +16,12 @@ export interface RepairsIssue { translation_placeholders?: Record; } +export const severitySort = { + critical: 1, + error: 2, + warning: 3, +}; + export const fetchRepairsIssues = async (hass: HomeAssistant) => hass.callWS<{ issues: RepairsIssue[] }>({ type: "repairs/list_issues", diff --git a/src/panels/config/dashboard/ha-config-dashboard.ts b/src/panels/config/dashboard/ha-config-dashboard.ts index 1ff795dafc..8ddcaad8ab 100644 --- a/src/panels/config/dashboard/ha-config-dashboard.ts +++ b/src/panels/config/dashboard/ha-config-dashboard.ts @@ -23,6 +23,11 @@ import "../../../components/ha-menu-button"; import "../../../components/ha-svg-icon"; import "../../../components/ha-tip"; import { CloudStatus } from "../../../data/cloud"; +import { + fetchRepairsIssues, + RepairsIssue, + severitySort, +} from "../../../data/repairs"; import { checkForEntityUpdates, filterUpdateEntitiesWithInstall, @@ -36,6 +41,7 @@ import { HomeAssistant } from "../../../types"; import { documentationUrl } from "../../../util/documentation-url"; import "../ha-config-section"; import { configSections } from "../ha-panel-config"; +import "../repairs/ha-config-repairs"; import "./ha-config-navigation"; import "./ha-config-updates"; @@ -118,6 +124,8 @@ class HaConfigDashboard extends LitElement { @state() private _tip?: string; + @state() private _repairsIssues: [RepairsIssue[], number] = [[], 0]; + private _pages = memoizeOne((clouStatus, isLoaded) => { const pages: PageNavigation[] = []; if (clouStatus && isLoaded) { @@ -137,6 +145,8 @@ class HaConfigDashboard extends LitElement { const [canInstallUpdates, totalUpdates] = this._filterUpdateEntitiesWithInstall(this.hass.states); + const [repairsIssues, totalRepairIssues] = this._repairsIssues; + return html` @@ -174,26 +184,55 @@ class HaConfigDashboard extends LitElement { .isWide=${this.isWide} full-width > - ${canInstallUpdates.length - ? html` - - ${totalUpdates > canInstallUpdates.length - ? html` - ${this.hass.localize( - "ui.panel.config.updates.more_updates", - { - count: totalUpdates - canInstallUpdates.length, - } - )} - ` - : ""} - ` + ${repairsIssues.length + ? html` + + + ${totalRepairIssues > repairsIssues.length + ? html` + + ${this.hass.localize( + "ui.panel.config.repairs.more_repairs", + { + count: totalRepairIssues - repairsIssues.length, + } + )} + + ` + : ""} + + ` : ""} + ${canInstallUpdates.length + ? html` + + + ${totalUpdates > canInstallUpdates.length + ? html` + + ${this.hass.localize( + "ui.panel.config.updates.more_updates", + { + count: totalUpdates - canInstallUpdates.length, + } + )} + + ` + : ""} + + ` + : ""} + { + const [, repairsIssues] = await Promise.all([ + this.hass.loadBackendTranslation("issues"), + fetchRepairsIssues(this.hass), + ]); + + this._repairsIssues = [ + repairsIssues.issues + .sort((a, b) => severitySort[a.severity] - severitySort[b.severity]) + .slice( + 0, + repairsIssues.issues.length === 3 ? repairsIssues.issues.length : 2 + ), + repairsIssues.issues.length, + ]; + } + private _showQuickBar(): void { showQuickBar(this, { commandMode: true, diff --git a/src/panels/config/repairs/ha-config-repairs.ts b/src/panels/config/repairs/ha-config-repairs.ts index 02463e64c8..6a6fa8f168 100644 --- a/src/panels/config/repairs/ha-config-repairs.ts +++ b/src/panels/config/repairs/ha-config-repairs.ts @@ -24,6 +24,9 @@ class HaConfigRepairs extends LitElement { @property({ attribute: false }) public repairsIssues?: RepairsIssue[]; + @property({ type: Number }) + public total?: number; + protected render(): TemplateResult { if (!this.repairsIssues?.length) { return html``; @@ -34,7 +37,7 @@ class HaConfigRepairs extends LitElement { return html`
${this.hass.localize("ui.panel.config.repairs.title", { - count: this.repairsIssues.length, + count: this.total || this.repairsIssues.length, })}
diff --git a/src/translations/en.json b/src/translations/en.json index 2ce29af81a..292c97078f 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -1231,6 +1231,7 @@ "description": "Find and fix issues with your Home Assistant instance", "title": "{count} {count, plural,\n one {repair}\n other {repairs}\n}", "no_repairs": "There are currently no repairs available", + "more_repairs": "+{count} repairs", "dialog": { "title": "Repair", "fix": "Repair",