diff --git a/src/data/recorder.ts b/src/data/recorder.ts index caa97fd29a..06b0ec91f4 100644 --- a/src/data/recorder.ts +++ b/src/data/recorder.ts @@ -34,11 +34,7 @@ export type StatisticsValidationResult = | StatisticsValidationResultEntityNotRecorded | StatisticsValidationResultEntityNoLongerRecorded | StatisticsValidationResultUnsupportedStateClass - | StatisticsValidationResultUnitsChanged - | StatisticsValidationResultUnitsChangedCanConvert - | StatisticsValidationResultUnsupportedUnitMetadata - | StatisticsValidationResultUnsupportedUnitMetadataCanConvert - | StatisticsValidationResultUnsupportedUnitState; + | StatisticsValidationResultUnitsChanged; export interface StatisticsValidationResultNoState { type: "no_state"; @@ -62,29 +58,9 @@ export interface StatisticsValidationResultUnsupportedStateClass { export interface StatisticsValidationResultUnitsChanged { type: "units_changed"; - data: { statistic_id: string; state_unit: string; metadata_unit: string }; -} - -export interface StatisticsValidationResultUnitsChangedCanConvert { - type: "units_changed_can_convert"; - data: { statistic_id: string; state_unit: string; metadata_unit: string }; -} - -export interface StatisticsValidationResultUnsupportedUnitMetadata { - type: "unsupported_unit_metadata"; data: { statistic_id: string; - device_class: string; - metadata_unit: string; - supported_unit: string; - }; -} - -export interface StatisticsValidationResultUnsupportedUnitMetadataCanConvert { - type: "unsupported_unit_metadata_can_convert"; - data: { - statistic_id: string; - device_class: string; + state_unit: string; metadata_unit: string; supported_unit: string; }; @@ -107,11 +83,6 @@ export interface StatisticsUnitConfiguration { volume?: "ft³" | "m³"; } -export interface StatisticsValidationResultUnsupportedUnitState { - type: "unsupported_unit_state"; - data: { statistic_id: string; device_class: string; metadata_unit: string }; -} - export interface StatisticsValidationResults { [statisticId: string]: StatisticsValidationResult[]; } @@ -167,19 +138,6 @@ export const updateStatisticsMetadata = ( unit_of_measurement, }); -export const changeStatisticUnit = ( - hass: HomeAssistant, - statistic_id: string, - old_unit_of_measurement: string | null, - new_unit_of_measurement: string | null -) => - hass.callWS({ - type: "recorder/change_statistics_unit", - statistic_id, - old_unit_of_measurement, - new_unit_of_measurement, - }); - export const clearStatistics = (hass: HomeAssistant, statistic_ids: string[]) => hass.callWS({ type: "recorder/clear_statistics", diff --git a/src/panels/developer-tools/statistics/developer-tools-statistics.ts b/src/panels/developer-tools/statistics/developer-tools-statistics.ts index 7cd162ccfe..7ae5269b3a 100644 --- a/src/panels/developer-tools/statistics/developer-tools-statistics.ts +++ b/src/panels/developer-tools/statistics/developer-tools-statistics.ts @@ -25,18 +25,13 @@ import { haStyle } from "../../../resources/styles"; import { HomeAssistant } from "../../../types"; import { showStatisticsAdjustSumDialog } from "./show-dialog-statistics-adjust-sum"; 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, - units_changed_can_convert: 4, - units_changed: 5, - unsupported_unit_metadata_can_convert: 6, - unsupported_unit_metadata: 7, + unsupported_state_class: 2, + units_changed: 3, }; @customElement("developer-tools-statistics") class HaPanelDevStatistics extends SubscribeMixin(LitElement) { @@ -310,42 +305,6 @@ class HaPanelDevStatistics extends SubscribeMixin(LitElement) { }, }); break; - case "unsupported_unit_metadata": - showFixStatisticsUnsupportedUnitMetadataDialog(this, { - issue, - fixedCallback: () => { - this._validateStatistics(); - }, - }); - break; - case "unsupported_unit_metadata_can_convert": - showFixStatisticsUnsupportedUnitMetadataDialog(this, { - issue, - fixedCallback: () => { - this._validateStatistics(); - }, - }); - break; - case "unsupported_unit_state": - showAlertDialog(this, { - title: "Unsupported unit", - text: html`The unit of your entity is not a supported unit for the - device class of the entity, ${issue.data.device_class}. -
Statistics can not be generated until this entity has a - supported unit.

If this unit was provided by an - integration, this is a bug. Please report an issue.

If - you have set this unit yourself, and want to have statistics - generated, make sure the unit matches the device class. The - supported units are documented in the - - developer documentation.`, - }); - break; case "units_changed": showFixStatisticsUnitsChangedDialog(this, { issue, @@ -354,14 +313,6 @@ class HaPanelDevStatistics extends SubscribeMixin(LitElement) { }, }); break; - case "units_changed_can_convert": - showFixStatisticsUnitsChangedDialog(this, { - issue, - fixedCallback: () => { - this._validateStatistics(); - }, - }); - break; default: showAlertDialog(this, { title: "Fix issue", diff --git a/src/panels/developer-tools/statistics/dialog-statistics-fix-units-changed.ts b/src/panels/developer-tools/statistics/dialog-statistics-fix-units-changed.ts index f475ca7967..4ca3912f48 100644 --- a/src/panels/developer-tools/statistics/dialog-statistics-fix-units-changed.ts +++ b/src/panels/developer-tools/statistics/dialog-statistics-fix-units-changed.ts @@ -6,7 +6,6 @@ import { fireEvent } from "../../../common/dom/fire_event"; import { haStyle, haStyleDialog } from "../../../resources/styles"; import { HomeAssistant } from "../../../types"; import { - changeStatisticUnit, clearStatistics, updateStatisticsMetadata, } from "../../../data/recorder"; @@ -37,7 +36,7 @@ export class DialogStatisticsFixUnitsChanged extends LitElement { if (!this._params) { return html``; } - + /* eslint-disable lit/quoted-expressions */ return html`

- The unit of this entity changed, we can't store values in multiple - units.
If the historic statistic values have a wrong unit, you - can update the units of the old values. The values will not be - updated.
Otherwise you can choose to delete all historic - statistic values, and start over. + The unit of this entity changed to + '${this._params.issue.data.state_unit}' which can't be converted to + the previously stored unit, + '${this._params.issue.data.metadata_unit}'. +
If the historic statistic values have a wrong unit, you can + update the units of the old values. The values will not be updated.
Otherwise + you can choose to delete all historic statistic values, and start + over.

How do you want to fix this issue?

@@ -81,20 +83,6 @@ export class DialogStatisticsFixUnitsChanged extends LitElement { @change=${this._handleActionChanged} > - ${this._params.issue.type === "units_changed_can_convert" - ? html` - - ` - : ""} ${this.hass.localize( @@ -106,6 +94,7 @@ export class DialogStatisticsFixUnitsChanged extends LitElement {
`; + /* eslint-enable lit/quoted-expressions */ } private _handleActionChanged(ev): void { @@ -121,13 +110,6 @@ export class DialogStatisticsFixUnitsChanged extends LitElement { this._params!.issue.data.statistic_id, this._params!.issue.data.state_unit ); - } else if (this._action === "change") { - await changeStatisticUnit( - this.hass, - this._params!.issue.data.statistic_id, - this._params!.issue.data.metadata_unit, - this._params!.issue.data.state_unit - ); } this._params?.fixedCallback(); this.closeDialog(); diff --git a/src/panels/developer-tools/statistics/dialog-statistics-fix-unsupported-unit-meta.ts b/src/panels/developer-tools/statistics/dialog-statistics-fix-unsupported-unit-meta.ts deleted file mode 100644 index 084aa81577..0000000000 --- a/src/panels/developer-tools/statistics/dialog-statistics-fix-unsupported-unit-meta.ts +++ /dev/null @@ -1,99 +0,0 @@ -import "@material/mwc-button/mwc-button"; -import { LitElement, TemplateResult, html, CSSResultGroup } from "lit"; -import { customElement, property, state } from "lit/decorators"; -import "../../../components/ha-dialog"; -import { fireEvent } from "../../../common/dom/fire_event"; -import { haStyle, haStyleDialog } from "../../../resources/styles"; -import { HomeAssistant } from "../../../types"; -import { - changeStatisticUnit, - updateStatisticsMetadata, -} from "../../../data/recorder"; -import "../../../components/ha-formfield"; -import "../../../components/ha-radio"; -import type { DialogStatisticsUnsupportedUnitMetaParams } from "./show-dialog-statistics-fix-unsupported-unit-meta"; - -@customElement("dialog-statistics-fix-unsupported-unit-meta") -export class DialogStatisticsFixUnsupportedUnitMetadata extends LitElement { - @property({ attribute: false }) public hass!: HomeAssistant; - - @state() private _params?: DialogStatisticsUnsupportedUnitMetaParams; - - public showDialog(params: DialogStatisticsUnsupportedUnitMetaParams): void { - this._params = params; - } - - public closeDialog(): void { - this._params = undefined; - fireEvent(this, "dialog-closed", { dialog: this.localName }); - } - - protected render(): TemplateResult | void { - if (!this._params) { - return html``; - } - - return html` - -

- The unit ${this._params.issue.data.metadata_unit} of the statistics in - your database for this entity is not a supported unit for the device - class of the entity, ${this._params.issue.data.device_class}. It - should be ${this._params.issue.data.supported_unit}. -

-

- ${this._params.issue.type === "unsupported_unit_metadata_can_convert" - ? `Do you want to convert all the historic statistic values to - ${this._params.issue.data.supported_unit}?` - : `Do you want to update the unit of the history statistics to - ${this._params.issue.data.supported_unit} without converting the - values?`} -

- - - Fix - - - ${this.hass.localize("ui.common.close")} - -
- `; - } - - private async _fixIssue(): Promise { - if (this._params!.issue.type === "unsupported_unit_metadata_can_convert") { - await changeStatisticUnit( - this.hass, - this._params!.issue.data.statistic_id, - this._params!.issue.data.metadata_unit, - this._params!.issue.data.supported_unit - ); - } else { - await updateStatisticsMetadata( - this.hass, - this._params!.issue.data.statistic_id, - this._params!.issue.data.supported_unit - ); - } - this._params?.fixedCallback(); - this.closeDialog(); - } - - static get styles(): CSSResultGroup { - return [haStyle, haStyleDialog]; - } -} - -declare global { - interface HTMLElementTagNameMap { - "dialog-statistics-fix-unsupported-unit-meta": DialogStatisticsFixUnsupportedUnitMetadata; - } -} diff --git a/src/panels/developer-tools/statistics/show-dialog-statistics-fix-units-changed.ts b/src/panels/developer-tools/statistics/show-dialog-statistics-fix-units-changed.ts index 974cdc1284..1b6d7ee116 100644 --- a/src/panels/developer-tools/statistics/show-dialog-statistics-fix-units-changed.ts +++ b/src/panels/developer-tools/statistics/show-dialog-statistics-fix-units-changed.ts @@ -1,16 +1,11 @@ import { fireEvent } from "../../../common/dom/fire_event"; -import { - StatisticsValidationResultUnitsChanged, - StatisticsValidationResultUnitsChangedCanConvert, -} from "../../../data/recorder"; +import { StatisticsValidationResultUnitsChanged } from "../../../data/recorder"; export const loadFixUnitsDialog = () => import("./dialog-statistics-fix-units-changed"); export interface DialogStatisticsUnitsChangedParams { - issue: - | StatisticsValidationResultUnitsChanged - | StatisticsValidationResultUnitsChangedCanConvert; + issue: StatisticsValidationResultUnitsChanged; fixedCallback: () => void; } diff --git a/src/panels/developer-tools/statistics/show-dialog-statistics-fix-unsupported-unit-meta.ts b/src/panels/developer-tools/statistics/show-dialog-statistics-fix-unsupported-unit-meta.ts deleted file mode 100644 index de0aaf287c..0000000000 --- a/src/panels/developer-tools/statistics/show-dialog-statistics-fix-unsupported-unit-meta.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { fireEvent } from "../../../common/dom/fire_event"; -import { - StatisticsValidationResultUnsupportedUnitMetadata, - StatisticsValidationResultUnsupportedUnitMetadataCanConvert, -} from "../../../data/recorder"; - -export const loadFixUnsupportedUnitMetaDialog = () => - import("./dialog-statistics-fix-unsupported-unit-meta"); - -export interface DialogStatisticsUnsupportedUnitMetaParams { - issue: - | StatisticsValidationResultUnsupportedUnitMetadata - | StatisticsValidationResultUnsupportedUnitMetadataCanConvert; - fixedCallback: () => void; -} - -export const showFixStatisticsUnsupportedUnitMetadataDialog = ( - element: HTMLElement, - detailParams: DialogStatisticsUnsupportedUnitMetaParams -): void => { - fireEvent(element, "show-dialog", { - dialogTag: "dialog-statistics-fix-unsupported-unit-meta", - dialogImport: loadFixUnsupportedUnitMetaDialog, - dialogParams: detailParams, - }); -}; diff --git a/src/translations/en.json b/src/translations/en.json index b2c6fbd067..0a65f4d19a 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -4571,9 +4571,6 @@ "no_issue": "No issue", "issues": { "units_changed": "The unit of this entity changed from ''{metadata_unit}'' to ''{state_unit}''.", - "units_changed_can_convert": "The unit of this entity changed from ''{metadata_unit}'' to ''{state_unit}''.", - "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_no_longer_recorded": "This entity is no longer being recorded.", @@ -4584,7 +4581,6 @@ "units_changed": { "title": "The unit of this entity changed", "update": "Update the unit of the historic statistic values from ''{metadata_unit}'' to ''{state_unit}'', without converting.", - "change": "Convert all the historic statistic values from ''{metadata_unit}'' to ''{state_unit}''", "clear": "Delete all old statistic data for this entity" } },