diff --git a/src/data/history.ts b/src/data/history.ts index a163ea4708..fed6abaf89 100644 --- a/src/data/history.ts +++ b/src/data/history.ts @@ -77,12 +77,24 @@ export interface StatisticsMetaData { } export type StatisticsValidationResult = + | StatisticsValidationResultNoState | StatisticsValidationResultEntityNotRecorded + | StatisticsValidationResultEntityNoLongerRecorded | StatisticsValidationResultUnsupportedStateClass | StatisticsValidationResultUnitsChanged | StatisticsValidationResultUnsupportedUnitMetadata | StatisticsValidationResultUnsupportedUnitState; +export interface StatisticsValidationResultNoState { + type: "no_state"; + data: { statistic_id: string }; +} + +export interface StatisticsValidationResultEntityNoLongerRecorded { + type: "entity_no_longer_recorded"; + data: { statistic_id: string }; +} + export interface StatisticsValidationResultEntityNotRecorded { type: "entity_not_recorded"; data: { statistic_id: string }; diff --git a/src/panels/developer-tools/statistics/developer-tools-statistics.ts b/src/panels/developer-tools/statistics/developer-tools-statistics.ts index 66fbd5354b..71963bfe6e 100644 --- a/src/panels/developer-tools/statistics/developer-tools-statistics.ts +++ b/src/panels/developer-tools/statistics/developer-tools-statistics.ts @@ -8,18 +8,24 @@ import { computeStateName } from "../../../common/entity/compute_state_name"; import "../../../components/data-table/ha-data-table"; import type { DataTableColumnContainer } from "../../../components/data-table/ha-data-table"; import { + clearStatistics, getStatisticIds, StatisticsMetaData, StatisticsValidationResult, validateStatistics, } from "../../../data/history"; -import { showAlertDialog } from "../../../dialogs/generic/show-dialog-box"; +import { + showAlertDialog, + showConfirmationDialog, +} from "../../../dialogs/generic/show-dialog-box"; import { haStyle } from "../../../resources/styles"; import { HomeAssistant } from "../../../types"; import { showFixStatisticsUnitsChangedDialog } from "./show-dialog-statistics-fix-units-changed"; import { showFixStatisticsUnsupportedUnitMetadataDialog } from "./show-dialog-statistics-fix-unsupported-unit-meta"; const FIX_ISSUES_ORDER = { + no_state: 0, + entity_no_longer_recorded: 1, entity_not_recorded: 1, unsupported_unit_state: 2, unsupported_state_class: 3, @@ -103,7 +109,7 @@ class HaPanelDevStatistics extends LitElement {
Do you want to permanently remove + the long term statistics of ${issue.data.statistic_id} from your + database?`, + confirm: async () => { + await clearStatistics(this.hass, [issue.data.statistic_id]); + this._validateStatistics(); + }, + }); + break; case "entity_not_recorded": showAlertDialog(this, { title: "Entity not recorded", @@ -172,6 +192,24 @@ class HaPanelDevStatistics extends LitElement { for more information.`, }); break; + case "entity_no_longer_recorded": + showAlertDialog(this, { + title: "Entity no longer recorded", + text: html`We have generated statistics for this entity in the past, + but state changes of this entity are no longer recorded, therefore, + we can not track long term statistics for it anymore. +

You probably excluded this entity, or have just included + some entities.

See the + + recorder documentation + for more information.`, + }); + break; case "unsupported_state_class": showAlertDialog(this, { title: "Unsupported state class", diff --git a/src/translations/en.json b/src/translations/en.json index b842ec456e..94abbe1877 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -3879,7 +3879,9 @@ "unsupported_unit_state": "The unit (''{state_unit}'') of this entity doesn't match a unit of device class ''{device_class}''.", "unsupported_unit_metadata": "The unit (''{metadata_unit}'') of the recorded statistics doesn't match the supported unit ''{supported_unit}'' of device class ''{device_class}''.", "unsupported_state_class": "The state class ''{state_class}'' of this entity is not supported.", - "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.", + "no_state": "There is no state available for this entity." }, "fix_issue": { "fix": "Fix issue",