mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 08:16:36 +00:00
add support for stats units_changed_can_convert
issues (#13902)
This commit is contained in:
parent
1b480248d1
commit
d9f1540115
@ -35,6 +35,7 @@ export type StatisticsValidationResult =
|
||||
| StatisticsValidationResultEntityNoLongerRecorded
|
||||
| StatisticsValidationResultUnsupportedStateClass
|
||||
| StatisticsValidationResultUnitsChanged
|
||||
| StatisticsValidationResultUnitsChangedCanConvert
|
||||
| StatisticsValidationResultUnsupportedUnitMetadata
|
||||
| StatisticsValidationResultUnsupportedUnitState;
|
||||
|
||||
@ -63,6 +64,11 @@ export interface StatisticsValidationResultUnitsChanged {
|
||||
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: {
|
||||
@ -150,6 +156,19 @@ 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<void>({
|
||||
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<void>({
|
||||
type: "recorder/clear_statistics",
|
||||
|
@ -33,8 +33,9 @@ const FIX_ISSUES_ORDER = {
|
||||
entity_not_recorded: 1,
|
||||
unsupported_unit_state: 2,
|
||||
unsupported_state_class: 3,
|
||||
units_changed: 4,
|
||||
unsupported_unit_metadata: 5,
|
||||
units_changed_can_convert: 4,
|
||||
units_changed: 5,
|
||||
unsupported_unit_metadata: 6,
|
||||
};
|
||||
@customElement("developer-tools-statistics")
|
||||
class HaPanelDevStatistics extends SubscribeMixin(LitElement) {
|
||||
@ -350,6 +351,14 @@ class HaPanelDevStatistics extends SubscribeMixin(LitElement) {
|
||||
},
|
||||
});
|
||||
break;
|
||||
case "units_changed_can_convert":
|
||||
showFixStatisticsUnitsChangedDialog(this, {
|
||||
issue,
|
||||
fixedCallback: () => {
|
||||
this._validateStatistics();
|
||||
},
|
||||
});
|
||||
break;
|
||||
default:
|
||||
showAlertDialog(this, {
|
||||
title: "Fix issue",
|
||||
|
@ -6,6 +6,7 @@ import { fireEvent } from "../../../common/dom/fire_event";
|
||||
import { haStyle, haStyleDialog } from "../../../resources/styles";
|
||||
import { HomeAssistant } from "../../../types";
|
||||
import {
|
||||
changeStatisticUnit,
|
||||
clearStatistics,
|
||||
updateStatisticsMetadata,
|
||||
} from "../../../data/recorder";
|
||||
@ -19,7 +20,7 @@ export class DialogStatisticsFixUnitsChanged extends LitElement {
|
||||
|
||||
@state() private _params?: DialogStatisticsUnitsChangedParams;
|
||||
|
||||
@state() private _action?: "update" | "clear";
|
||||
@state() private _action?: "update" | "clear" | "change";
|
||||
|
||||
public showDialog(params: DialogStatisticsUnitsChangedParams): void {
|
||||
this._params = params;
|
||||
@ -80,6 +81,20 @@ export class DialogStatisticsFixUnitsChanged extends LitElement {
|
||||
@change=${this._handleActionChanged}
|
||||
></ha-radio>
|
||||
</ha-formfield>
|
||||
${this._params.issue.type === "units_changed_can_convert"
|
||||
? html`<ha-formfield
|
||||
.label=${this.hass.localize(
|
||||
`ui.panel.developer-tools.tabs.statistics.fix_issue.units_changed.change`
|
||||
)}
|
||||
>
|
||||
<ha-radio
|
||||
value="change"
|
||||
name="action"
|
||||
.checked=${this._action === "change"}
|
||||
@change=${this._handleActionChanged}
|
||||
></ha-radio>
|
||||
</ha-formfield>`
|
||||
: ""}
|
||||
|
||||
<mwc-button slot="primaryAction" @click=${this._fixIssue}>
|
||||
${this.hass.localize(
|
||||
@ -100,12 +115,19 @@ export class DialogStatisticsFixUnitsChanged extends LitElement {
|
||||
private async _fixIssue(): Promise<void> {
|
||||
if (this._action === "clear") {
|
||||
await clearStatistics(this.hass, [this._params!.issue.data.statistic_id]);
|
||||
} else {
|
||||
} else if (this._action === "update") {
|
||||
await updateStatisticsMetadata(
|
||||
this.hass,
|
||||
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();
|
||||
|
@ -1,11 +1,16 @@
|
||||
import { fireEvent } from "../../../common/dom/fire_event";
|
||||
import { StatisticsValidationResultUnitsChanged } from "../../../data/recorder";
|
||||
import {
|
||||
StatisticsValidationResultUnitsChanged,
|
||||
StatisticsValidationResultUnitsChangedCanConvert,
|
||||
} from "../../../data/recorder";
|
||||
|
||||
export const loadFixUnitsDialog = () =>
|
||||
import("./dialog-statistics-fix-units-changed");
|
||||
|
||||
export interface DialogStatisticsUnitsChangedParams {
|
||||
issue: StatisticsValidationResultUnitsChanged;
|
||||
issue:
|
||||
| StatisticsValidationResultUnitsChanged
|
||||
| StatisticsValidationResultUnitsChangedCanConvert;
|
||||
fixedCallback: () => void;
|
||||
}
|
||||
|
||||
|
@ -4568,6 +4568,7 @@
|
||||
"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.",
|
||||
@ -4579,7 +4580,8 @@
|
||||
"fix": "Fix issue",
|
||||
"units_changed": {
|
||||
"title": "The unit of this entity changed",
|
||||
"update": "Update the historic statistic values from ''{metadata_unit}'' to ''{state_unit}''",
|
||||
"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"
|
||||
}
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user