Improve statistics issues (#22110)

This commit is contained in:
Erik Montnemery 2024-09-27 11:05:30 +02:00 committed by GitHub
parent 49576189af
commit e778a9aa1d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 25 additions and 28 deletions

View File

@ -50,7 +50,7 @@ export interface StatisticsMetaData {
export const STATISTIC_TYPES: StatisticsValidationResult["type"][] = [ export const STATISTIC_TYPES: StatisticsValidationResult["type"][] = [
"entity_not_recorded", "entity_not_recorded",
"entity_no_longer_recorded", "entity_no_longer_recorded",
"unsupported_state_class", "state_class_removed",
"units_changed", "units_changed",
"no_state", "no_state",
]; ];
@ -59,7 +59,7 @@ export type StatisticsValidationResult =
| StatisticsValidationResultNoState | StatisticsValidationResultNoState
| StatisticsValidationResultEntityNotRecorded | StatisticsValidationResultEntityNotRecorded
| StatisticsValidationResultEntityNoLongerRecorded | StatisticsValidationResultEntityNoLongerRecorded
| StatisticsValidationResultUnsupportedStateClass | StatisticsValidationResultStateClassRemoved
| StatisticsValidationResultUnitsChanged; | StatisticsValidationResultUnitsChanged;
export interface StatisticsValidationResultNoState { export interface StatisticsValidationResultNoState {
@ -77,9 +77,9 @@ export interface StatisticsValidationResultEntityNotRecorded {
data: { statistic_id: string }; data: { statistic_id: string };
} }
export interface StatisticsValidationResultUnsupportedStateClass { export interface StatisticsValidationResultStateClassRemoved {
type: "unsupported_state_class"; type: "state_class_removed";
data: { statistic_id: string; state_class: string }; data: { statistic_id: string };
} }
export interface StatisticsValidationResultUnitsChanged { export interface StatisticsValidationResultUnitsChanged {

View File

@ -26,7 +26,7 @@ const FIX_ISSUES_ORDER = {
no_state: 0, no_state: 0,
entity_no_longer_recorded: 1, entity_no_longer_recorded: 1,
entity_not_recorded: 1, entity_not_recorded: 1,
unsupported_state_class: 2, state_class_removed: 2,
units_changed: 3, units_changed: 3,
}; };
@ -273,11 +273,9 @@ class HaPanelDevStatistics extends SubscribeMixin(LitElement) {
); );
if ( if (
result && result &&
[ ["no_state", "entity_no_longer_recorded", "state_class_removed"].includes(
"no_state", issue.type
"entity_no_longer_recorded", )
"unsupported_state_class",
].includes(issue.type)
) { ) {
this._deletedStatistics.add(issue.data.statistic_id); this._deletedStatistics.add(issue.data.statistic_id);
} }

View File

@ -103,31 +103,30 @@ export const fixStatisticsIssue = async (
await clearStatistics(hass, [issue.data.statistic_id]); await clearStatistics(hass, [issue.data.statistic_id]);
}, },
}); });
case "unsupported_state_class": case "state_class_removed":
return showConfirmationDialog(element, { return showConfirmationDialog(element, {
title: localize( 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( 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), name: getStatisticLabel(hass, issue.data.statistic_id, undefined),
statistic_id: issue.data.statistic_id, statistic_id: issue.data.statistic_id,
state_class: issue.data.state_class,
} }
)}<br /><br /> )}<br /><br />
${localize( ${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"
)} )}
<ul> <ul>
<li> <li>
${localize( ${localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.unsupported_state_class.info_text_3" "ui.panel.developer-tools.tabs.statistics.fix_issue.state_class_removed.info_text_3"
)} )}
</li> </li>
<li> <li>
${localize( ${localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.unsupported_state_class.info_text_4" "ui.panel.developer-tools.tabs.statistics.fix_issue.state_class_removed.info_text_4"
)} )}
<a <a
href="https://developers.home-assistant.io/docs/core/entity/sensor/#long-term-statistics" href="https://developers.home-assistant.io/docs/core/entity/sensor/#long-term-statistics"
@ -135,18 +134,18 @@ export const fixStatisticsIssue = async (
rel="noreferrer noopener" rel="noreferrer noopener"
> >
${localize( ${localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.unsupported_state_class.info_text_4_link" "ui.panel.developer-tools.tabs.statistics.fix_issue.state_class_removed.info_text_4_link"
)}</a )}</a
> >
</li> </li>
<li> <li>
${localize( ${localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.unsupported_state_class.info_text_5" "ui.panel.developer-tools.tabs.statistics.fix_issue.state_class_removed.info_text_5"
)} )}
</li> </li>
</ul> </ul>
${localize( ${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 } { statistic_id: issue.data.statistic_id }
)}`, )}`,
confirmText: localize("ui.common.delete"), confirmText: localize("ui.common.delete"),

View File

@ -6949,7 +6949,7 @@
"no_issue": "No issue", "no_issue": "No issue",
"issues": { "issues": {
"units_changed": "The unit of this entity changed from ''{metadata_unit}'' to ''{state_unit}''.", "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_not_recorded": "This entity is excluded from being recorded.",
"entity_no_longer_recorded": "This entity is no longer being recorded.", "entity_no_longer_recorded": "This entity is no longer being recorded.",
"no_state": "There is no state available for this entity." "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_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." "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": { "state_class_removed": {
"title": "Unsupported state class", "title": "The entity no longer has a state class",
"info_text_1": "The state class of ''{name}'' ({statistic_id}), ''{state_class}'', is not supported.", "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_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_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 have set this state class yourself, please correct it.", "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_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?" "info_text_6": "Do you want to permanently delete the long term statistics of {statistic_id} from your database?"
}, },
"units_changed": { "units_changed": {