mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +00:00
Adjust statistics issues (#14022)
* Adjust statistics issues * Fix lint error * Quote units * prettier * screw lit/quoted-expressions Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
parent
ea286b6fac
commit
712ecbd13c
@ -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<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",
|
||||
|
@ -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}.
|
||||
<br />Statistics can not be generated until this entity has a
|
||||
supported unit.<br /><br />If this unit was provided by an
|
||||
integration, this is a bug. Please report an issue.<br /><br />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
|
||||
<a
|
||||
href="https://developers.home-assistant.io/docs/core/entity/sensor/#available-device-classes"
|
||||
target="_blank"
|
||||
rel="noreferrer noopener"
|
||||
>
|
||||
developer documentation</a
|
||||
>.`,
|
||||
});
|
||||
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",
|
||||
|
@ -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`
|
||||
<ha-dialog
|
||||
open
|
||||
@ -47,11 +46,14 @@ export class DialogStatisticsFixUnitsChanged extends LitElement {
|
||||
)}
|
||||
>
|
||||
<p>
|
||||
The unit of this entity changed, we can't store values in multiple
|
||||
units. <br />If the historic statistic values have a wrong unit, you
|
||||
can update the units of the old values. The values will not be
|
||||
updated.<br />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}'.
|
||||
<br />If the historic statistic values have a wrong unit, you can
|
||||
update the units of the old values. The values will not be updated.<br />Otherwise
|
||||
you can choose to delete all historic statistic values, and start
|
||||
over.
|
||||
</p>
|
||||
|
||||
<h3>How do you want to fix this issue?</h3>
|
||||
@ -81,20 +83,6 @@ 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(
|
||||
@ -106,6 +94,7 @@ export class DialogStatisticsFixUnitsChanged extends LitElement {
|
||||
</mwc-button>
|
||||
</ha-dialog>
|
||||
`;
|
||||
/* 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();
|
||||
|
@ -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`
|
||||
<ha-dialog
|
||||
open
|
||||
@closed=${this.closeDialog}
|
||||
heading="Unsupported unit in recorded statistics"
|
||||
>
|
||||
<p>
|
||||
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}.
|
||||
</p>
|
||||
<p>
|
||||
${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?`}
|
||||
</p>
|
||||
|
||||
<mwc-button
|
||||
slot="primaryAction"
|
||||
@click=${this._fixIssue}
|
||||
dialogInitialFocus
|
||||
>
|
||||
Fix
|
||||
</mwc-button>
|
||||
<mwc-button slot="secondaryAction" @click=${this.closeDialog}>
|
||||
${this.hass.localize("ui.common.close")}
|
||||
</mwc-button>
|
||||
</ha-dialog>
|
||||
`;
|
||||
}
|
||||
|
||||
private async _fixIssue(): Promise<void> {
|
||||
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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
});
|
||||
};
|
@ -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"
|
||||
}
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user