From e778a9aa1d781146508cace47648b513e86b5e34 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Fri, 27 Sep 2024 11:05:30 +0200 Subject: [PATCH] Improve statistics issues (#22110) --- src/data/recorder.ts | 10 +++++----- .../statistics/developer-tools-statistics.ts | 10 ++++------ .../statistics/fix-statistics.ts | 19 +++++++++---------- src/translations/en.json | 14 +++++++------- 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/src/data/recorder.ts b/src/data/recorder.ts index f4ab0cb804..1b89af2834 100644 --- a/src/data/recorder.ts +++ b/src/data/recorder.ts @@ -50,7 +50,7 @@ export interface StatisticsMetaData { export const STATISTIC_TYPES: StatisticsValidationResult["type"][] = [ "entity_not_recorded", "entity_no_longer_recorded", - "unsupported_state_class", + "state_class_removed", "units_changed", "no_state", ]; @@ -59,7 +59,7 @@ export type StatisticsValidationResult = | StatisticsValidationResultNoState | StatisticsValidationResultEntityNotRecorded | StatisticsValidationResultEntityNoLongerRecorded - | StatisticsValidationResultUnsupportedStateClass + | StatisticsValidationResultStateClassRemoved | StatisticsValidationResultUnitsChanged; export interface StatisticsValidationResultNoState { @@ -77,9 +77,9 @@ export interface StatisticsValidationResultEntityNotRecorded { data: { statistic_id: string }; } -export interface StatisticsValidationResultUnsupportedStateClass { - type: "unsupported_state_class"; - data: { statistic_id: string; state_class: string }; +export interface StatisticsValidationResultStateClassRemoved { + type: "state_class_removed"; + data: { statistic_id: string }; } export interface StatisticsValidationResultUnitsChanged { diff --git a/src/panels/developer-tools/statistics/developer-tools-statistics.ts b/src/panels/developer-tools/statistics/developer-tools-statistics.ts index a169eeb179..8baafaf909 100644 --- a/src/panels/developer-tools/statistics/developer-tools-statistics.ts +++ b/src/panels/developer-tools/statistics/developer-tools-statistics.ts @@ -26,7 +26,7 @@ const FIX_ISSUES_ORDER = { no_state: 0, entity_no_longer_recorded: 1, entity_not_recorded: 1, - unsupported_state_class: 2, + state_class_removed: 2, units_changed: 3, }; @@ -273,11 +273,9 @@ class HaPanelDevStatistics extends SubscribeMixin(LitElement) { ); if ( result && - [ - "no_state", - "entity_no_longer_recorded", - "unsupported_state_class", - ].includes(issue.type) + ["no_state", "entity_no_longer_recorded", "state_class_removed"].includes( + issue.type + ) ) { this._deletedStatistics.add(issue.data.statistic_id); } diff --git a/src/panels/developer-tools/statistics/fix-statistics.ts b/src/panels/developer-tools/statistics/fix-statistics.ts index 8dd140e718..0329cf77be 100644 --- a/src/panels/developer-tools/statistics/fix-statistics.ts +++ b/src/panels/developer-tools/statistics/fix-statistics.ts @@ -103,31 +103,30 @@ export const fixStatisticsIssue = async ( await clearStatistics(hass, [issue.data.statistic_id]); }, }); - case "unsupported_state_class": + case "state_class_removed": return showConfirmationDialog(element, { title: localize( - "ui.panel.developer-tools.tabs.statistics.fix_issue.unsupported_state_class.title" + "ui.panel.developer-tools.tabs.statistics.fix_issue.state_class_removed.title" ), text: html`${localize( - "ui.panel.developer-tools.tabs.statistics.fix_issue.unsupported_state_class.info_text_1", + "ui.panel.developer-tools.tabs.statistics.fix_issue.state_class_removed.info_text_1", { name: getStatisticLabel(hass, issue.data.statistic_id, undefined), statistic_id: issue.data.statistic_id, - state_class: issue.data.state_class, } )}

${localize( - "ui.panel.developer-tools.tabs.statistics.fix_issue.unsupported_state_class.info_text_2" + "ui.panel.developer-tools.tabs.statistics.fix_issue.state_class_removed.info_text_2" )} ${localize( - "ui.panel.developer-tools.tabs.statistics.fix_issue.unsupported_state_class.info_text_6", + "ui.panel.developer-tools.tabs.statistics.fix_issue.state_class_removed.info_text_6", { statistic_id: issue.data.statistic_id } )}`, confirmText: localize("ui.common.delete"), diff --git a/src/translations/en.json b/src/translations/en.json index 20677c99f7..c885fc97a0 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -6949,7 +6949,7 @@ "no_issue": "No issue", "issues": { "units_changed": "The unit of this entity changed from ''{metadata_unit}'' to ''{state_unit}''.", - "unsupported_state_class": "The state class ''{state_class}'' of this entity is not supported.", + "state_class_removed": "This entity no longer has a state class", "entity_not_recorded": "This entity is excluded from being recorded.", "entity_no_longer_recorded": "This entity is no longer being recorded.", "no_state": "There is no state available for this entity." @@ -6978,14 +6978,14 @@ "info_text_3_link": "See the recorder documentation for more information.", "info_text_4": "If you no longer wish to keep the long term statistics recorded in the past, you may delete them now." }, - "unsupported_state_class": { - "title": "Unsupported state class", - "info_text_1": "The state class of ''{name}'' ({statistic_id}), ''{state_class}'', is not supported.", + "state_class_removed": { + "title": "The entity no longer has a state class", + "info_text_1": "We have generated statistics for ''{name}'' ({statistic_id}) in the past, but it no longer has a state class, therefore, we cannot track long term statistics for it anymore.", "info_text_2": "Statistics cannot be generated until this entity has a supported state class.", - "info_text_3": "If this state class was provided by an integration, this is a bug. Please report an issue.", - "info_text_4": "If you have set this state class yourself, please correct it.", + "info_text_3": "If the state class was previously provided by an integration, this might be a bug. Please report an issue.", + "info_text_4": "If you previously set the state class yourself, please correct it.", "info_text_4_link": "The different state classes and when to use which can be found in the developer documentation.", - "info_text_5": "If the state class has permanently changed, you may want to delete the long term statistics of it from your database.", + "info_text_5": "If the state class has permanently been removed, you may want to delete the long term statistics of it from your database.", "info_text_6": "Do you want to permanently delete the long term statistics of {statistic_id} from your database?" }, "units_changed": {