Add translations for the developer tools statistic issues (#18646)

This commit is contained in:
Simon Lamon 2023-11-16 18:16:51 +01:00 committed by GitHub
parent 3addfc3548
commit fb95de1f73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 230 additions and 89 deletions

View File

@ -27,6 +27,7 @@ import { HomeAssistant } from "../../../types";
import { showStatisticsAdjustSumDialog } from "./show-dialog-statistics-adjust-sum"; import { showStatisticsAdjustSumDialog } from "./show-dialog-statistics-adjust-sum";
import { showFixStatisticsUnitsChangedDialog } from "./show-dialog-statistics-fix-units-changed"; import { showFixStatisticsUnitsChangedDialog } from "./show-dialog-statistics-fix-units-changed";
import { computeRTLDirection } from "../../../common/util/compute_rtl"; import { computeRTLDirection } from "../../../common/util/compute_rtl";
import { documentationUrl } from "../../../util/documentation-url";
const FIX_ISSUES_ORDER = { const FIX_ISSUES_ORDER = {
no_state: 0, no_state: 0,
@ -266,13 +267,16 @@ class HaPanelDevStatistics extends SubscribeMixin(LitElement) {
switch (issue.type) { switch (issue.type) {
case "no_state": case "no_state":
showConfirmationDialog(this, { showConfirmationDialog(this, {
title: "Entity has no state", title: this.hass.localize(
text: html`This entity has no state at the moment, if this is an "ui.panel.developer-tools.tabs.statistics.fix_issue.no_state.title"
orphaned entity, you may want to remove the long term statistics of ),
it from your database.<br /><br />Do you want to permanently remove text: html`${this.hass.localize(
the long term statistics of ${issue.data.statistic_id} from your "ui.panel.developer-tools.tabs.statistics.fix_issue.no_state.info_text_1"
database?`, )}<br /><br />${this.hass.localize(
confirmText: this.hass.localize("ui.common.remove"), "ui.panel.developer-tools.tabs.statistics.fix_issue.no_state.info_text_2",
{ statistic_id: issue.data.statistic_id }
)}`,
confirmText: this.hass.localize("ui.common.delete"),
confirm: async () => { confirm: async () => {
await clearStatistics(this.hass, [issue.data.statistic_id]); await clearStatistics(this.hass, [issue.data.statistic_id]);
this._validateStatistics(); this._validateStatistics();
@ -281,60 +285,96 @@ class HaPanelDevStatistics extends SubscribeMixin(LitElement) {
break; break;
case "entity_not_recorded": case "entity_not_recorded":
showAlertDialog(this, { showAlertDialog(this, {
title: "Entity not recorded", title: this.hass.localize(
text: html`State changes of this entity are not recorded, therefore, "ui.panel.developer-tools.tabs.statistics.fix_issue.entity_not_recorded.title"
we cannot track long term statistics for it. <br /><br />You ),
probably excluded this entity, or have just included some text: html`${this.hass.localize(
entities.<br /><br />See the "ui.panel.developer-tools.tabs.statistics.fix_issue.entity_not_recorded.info_text_1"
)}<br /><br />${this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.entity_not_recorded.info_text_2"
)}<br /><br />
<a <a
href="https://www.home-assistant.io/integrations/recorder/#configure-filter" href=${documentationUrl(
this.hass,
"/integrations/recorder/#configure-filter"
)}
target="_blank" target="_blank"
rel="noreferrer noopener" rel="noreferrer noopener"
> >
recorder documentation</a ${this.hass.localize(
> "ui.panel.developer-tools.tabs.statistics.fix_issue.entity_not_recorded.info_text_3_link"
for more information.`, )}</a
>`,
}); });
break; break;
case "entity_no_longer_recorded": case "entity_no_longer_recorded":
showAlertDialog(this, { showAlertDialog(this, {
title: "Entity no longer recorded", title: this.hass.localize(
text: html`We have generated statistics for this entity in the past, "ui.panel.developer-tools.tabs.statistics.fix_issue.entity_no_longer_recorded.title"
but state changes of this entity are no longer recorded, therefore, ),
we cannot track long term statistics for it anymore. <br /><br />You text: html`${this.hass.localize(
probably excluded this entity, or have just included some "ui.panel.developer-tools.tabs.statistics.fix_issue.entity_no_longer_recorded.info_text_1"
entities.<br /><br />See the )}
${this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.entity_no_longer_recorded.info_text_2"
)}
<a <a
href="https://www.home-assistant.io/integrations/recorder/#configure-filter" href=${documentationUrl(
this.hass,
"/integrations/recorder/#configure-filter"
)}
target="_blank" target="_blank"
rel="noreferrer noopener" rel="noreferrer noopener"
> >
recorder documentation</a ${this.hass.localize(
> "ui.panel.developer-tools.tabs.statistics.fix_issue.entity_no_longer_recorded.info_text_3_link"
for more information.`, )}</a
>`,
}); });
break; break;
case "unsupported_state_class": case "unsupported_state_class":
showConfirmationDialog(this, { showConfirmationDialog(this, {
title: "Unsupported state class", title: this.hass.localize(
text: html`The state class of this entity, ${issue.data.state_class} "ui.panel.developer-tools.tabs.statistics.fix_issue.unsupported_state_class.title"
is not supported. <br />Statistics cannot be generated until this ),
entity has a supported state class.<br /><br />If this state class text: html`${this.hass.localize(
was provided by an integration, this is a bug. Please report an "ui.panel.developer-tools.tabs.statistics.fix_issue.unsupported_state_class.info_text_1",
issue.<br /><br />If you have set this state class yourself, please { state_class: issue.data.state_class }
correct it. The different state classes and when to use which can be )}<br /><br />
found in the ${this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.unsupported_state_class.info_text_2"
)}
<ul>
<li>
${this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.unsupported_state_class.info_text_3"
)}
</li>
<li>
${this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.unsupported_state_class.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"
target="_blank" target="_blank"
rel="noreferrer noopener" rel="noreferrer noopener"
> >
developer documentation</a ${this.hass.localize(
>. If the state class has permanently changed, you may want to "ui.panel.developer-tools.tabs.statistics.fix_issue.unsupported_state_class.info_text_4_link"
remove the long term statistics of it from your database.<br /><br />Do )}</a
you want to permanently remove the long term statistics of >
${issue.data.statistic_id} from your database?`, </li>
confirmText: this.hass.localize("ui.common.remove"), <li>
${this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.unsupported_state_class.info_text_5"
)}
</li>
</ul>
${this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.unsupported_state_class.info_text_6",
{ statistic_id: issue.data.statistic_id }
)}`,
confirmText: this.hass.localize("ui.common.delete"),
confirm: async () => { confirm: async () => {
await clearStatistics(this.hass, [issue.data.statistic_id]); await clearStatistics(this.hass, [issue.data.statistic_id]);
this._validateStatistics(); this._validateStatistics();
@ -351,8 +391,12 @@ class HaPanelDevStatistics extends SubscribeMixin(LitElement) {
break; break;
default: default:
showAlertDialog(this, { showAlertDialog(this, {
title: "Fix issue", title: this.hass.localize(
text: "Fixing this issue is not supported yet.", "ui.panel.developer-tools.tabs.statistics.fix_issue.no_support.title"
),
text: this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.no_support.info_text_1"
),
}); });
} }
}; };

View File

@ -34,8 +34,6 @@ import { HomeAssistant } from "../../../types";
import { showToast } from "../../../util/toast"; import { showToast } from "../../../util/toast";
import type { DialogStatisticsAdjustSumParams } from "./show-dialog-statistics-adjust-sum"; import type { DialogStatisticsAdjustSumParams } from "./show-dialog-statistics-adjust-sum";
/* eslint-disable lit/no-template-arrow */
@customElement("dialog-statistics-adjust-sum") @customElement("dialog-statistics-adjust-sum")
export class DialogStatisticsFixUnsupportedUnitMetadata extends LitElement { export class DialogStatisticsFixUnsupportedUnitMetadata extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public hass!: HomeAssistant;
@ -111,7 +109,9 @@ export class DialogStatisticsFixUnsupportedUnitMetadata extends LitElement {
scrimClickAction scrimClickAction
escapeKeyAction escapeKeyAction
@closed=${this.closeDialog} @closed=${this.closeDialog}
heading="Adjust a statistic" .heading=${this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.adjust_sum.title"
)}
> >
${content} ${content}
</ha-dialog> </ha-dialog>
@ -133,7 +133,11 @@ export class DialogStatisticsFixUnsupportedUnitMetadata extends LitElement {
if (!this._stats5min || !this._statsHour) { if (!this._stats5min || !this._statsHour) {
stats = html`<ha-circular-progress active></ha-circular-progress>`; stats = html`<ha-circular-progress active></ha-circular-progress>`;
} else if (this._statsHour.length < 1 && this._stats5min.length < 1) { } else if (this._statsHour.length < 1 && this._stats5min.length < 1) {
stats = html`<p>No statistics found for this period.</p>`; stats = html`<p>
${this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.adjust_sum.no_statistics_found"
)}
</p>`;
} else { } else {
const data = const data =
this._stats5min.length >= 1 ? this._stats5min : this._statsHour; this._stats5min.length >= 1 ? this._stats5min : this._statsHour;
@ -150,11 +154,8 @@ export class DialogStatisticsFixUnsupportedUnitMetadata extends LitElement {
<mwc-list-item <mwc-list-item
twoline twoline
hasMeta hasMeta
@click=${() => { .stat=${stat}
this._chosenStat = stat; @click=${this._setChosenStatistic}
this._origAmount = growth;
this._amount = growth;
}}
> >
<span>${growth} ${unit}</span> <span>${growth} ${unit}</span>
<span slot="secondary"> <span slot="secondary">
@ -173,15 +174,22 @@ export class DialogStatisticsFixUnsupportedUnitMetadata extends LitElement {
return html` return html`
<div class="text-content"> <div class="text-content">
Sometimes the statistics end up being incorrect for a specific point in ${this.hass.localize(
time. This can mess up your beautiful graphs! Select a time below to "ui.panel.developer-tools.tabs.statistics.fix_issue.adjust_sum.info_text_1"
find the bad moment and adjust the data. )}
</div> </div>
<div class="text-content"> <div class="text-content">
<b>Statistic:</b> ${this._params!.statistic.statistic_id} <b
>${this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.adjust_sum.statistic"
)}</b
>
${this._params!.statistic.statistic_id}
</div> </div>
<ha-selector-datetime <ha-selector-datetime
label="Pick a time" .label=${this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.adjust_sum.pick_a_time"
)}
.hass=${this.hass} .hass=${this.hass}
.selector=${this._dateTimeSelector} .selector=${this._dateTimeSelector}
.value=${this._moment} .value=${this._moment}
@ -196,6 +204,19 @@ export class DialogStatisticsFixUnsupportedUnitMetadata extends LitElement {
`; `;
} }
private _clearChosenStatistic() {
this._chosenStat = undefined;
}
private _setChosenStatistic(ev) {
const stat = ev.currentTarget.stat;
const growth = Math.round(stat.change! * 100) / 100;
this._chosenStat = stat;
this._origAmount = growth;
this._amount = growth;
}
private _dateTimeSelectorChanged(ev) { private _dateTimeSelectorChanged(ev) {
this._moment = ev.detail.value; this._moment = ev.detail.value;
this._fetchStats(); this._fetchStats();
@ -209,11 +230,20 @@ export class DialogStatisticsFixUnsupportedUnitMetadata extends LitElement {
); );
return html` return html`
<div class="text-content"> <div class="text-content">
<b>Statistic:</b> ${this._params!.statistic.statistic_id} <b
>${this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.adjust_sum.statistic"
)}</b
>
${this._params!.statistic.statistic_id}
</div> </div>
<div class="table-row"> <div class="table-row">
<span>Start</span> <span
>${this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.adjust_sum.start"
)}</span
>
<span <span
>${formatDateTime( >${formatDateTime(
new Date(this._chosenStat!.start), new Date(this._chosenStat!.start),
@ -224,7 +254,11 @@ export class DialogStatisticsFixUnsupportedUnitMetadata extends LitElement {
</div> </div>
<div class="table-row"> <div class="table-row">
<span>End</span> <span
>${this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.adjust_sum.end"
)}</span
>
<span <span
>${formatDateTime( >${formatDateTime(
new Date(this._chosenStat!.end), new Date(this._chosenStat!.end),
@ -235,35 +269,37 @@ export class DialogStatisticsFixUnsupportedUnitMetadata extends LitElement {
</div> </div>
<ha-selector-number <ha-selector-number
label="New Value" .label=${this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.adjust_sum.new_value"
)}
.hass=${this.hass} .hass=${this.hass}
.selector=${this._amountSelector(unit || undefined)} .selector=${this._amountSelector(unit || undefined)}
.value=${this._amount} .value=${this._amount}
.disabled=${this._busy} .disabled=${this._busy}
@value-changed=${(ev) => { @value-changed=${this._amountChanged}
this._amount = ev.detail.value;
}}
></ha-selector-number> ></ha-selector-number>
<mwc-button <mwc-button
slot="primaryAction" slot="primaryAction"
label="Adjust" .label=${this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.adjust_sum.adjust"
)}
.disabled=${this._busy} .disabled=${this._busy}
@click=${() => { @click=${this._fixIssue}
this._fixIssue();
}}
></mwc-button> ></mwc-button>
<mwc-button <mwc-button
slot="secondaryAction" slot="secondaryAction"
.label=${this.hass.localize("ui.common.back")} .label=${this.hass.localize("ui.common.back")}
.disabled=${this._busy} .disabled=${this._busy}
@click=${() => { @click=${this._clearChosenStatistic}
this._chosenStat = undefined;
}}
></mwc-button> ></mwc-button>
`; `;
} }
private _amountChanged(ev) {
this._amount = ev.detail.value;
}
private async _fetchStats(): Promise<void> { private async _fetchStats(): Promise<void> {
this._stats5min = undefined; this._stats5min = undefined;
this._statsHour = undefined; this._statsHour = undefined;
@ -331,12 +367,17 @@ export class DialogStatisticsFixUnsupportedUnitMetadata extends LitElement {
} catch (err: any) { } catch (err: any) {
this._busy = false; this._busy = false;
showAlertDialog(this, { showAlertDialog(this, {
text: `Error adjusting sum: ${err.message || err}`, text: this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.adjust_sum.error_sum_adjusted",
{ message: err.message || err }
),
}); });
return; return;
} }
showToast(this, { showToast(this, {
message: "Statistic sum adjusted", message: this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.adjust_sum.sum_adjusted"
),
}); });
this.closeDialog(); this.closeDialog();
} }

View File

@ -36,7 +36,7 @@ export class DialogStatisticsFixUnitsChanged extends LitElement {
if (!this._params) { if (!this._params) {
return nothing; return nothing;
} }
/* eslint-disable lit/quoted-expressions */
return html` return html`
<ha-dialog <ha-dialog
open open
@ -46,17 +46,26 @@ export class DialogStatisticsFixUnitsChanged extends LitElement {
)} )}
> >
<p> <p>
The unit of this entity changed to ${this.hass.localize(
'${this._params.issue.data.state_unit}' which can't be converted to "ui.panel.developer-tools.tabs.statistics.fix_issue.units_changed.info_text_1",
the previously stored unit, {
'${this._params.issue.data.metadata_unit}'. current_unit: this._params.issue.data.state_unit,
<br />If the historic statistic values have a wrong unit, you can previous_unit: this._params.issue.data.metadata_unit,
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 )}<br />
over. ${this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.units_changed.info_text_2"
)}<br />
${this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.units_changed.info_text_3"
)}
</p> </p>
<h3>How do you want to fix this issue?</h3> <h3>
${this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.units_changed.how_to_fix"
)}
</h3>
<ha-formfield <ha-formfield
.label=${this.hass.localize( .label=${this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.units_changed.update", "ui.panel.developer-tools.tabs.statistics.fix_issue.units_changed.update",
@ -94,7 +103,6 @@ export class DialogStatisticsFixUnitsChanged extends LitElement {
</mwc-button> </mwc-button>
</ha-dialog> </ha-dialog>
`; `;
/* eslint-enable lit/quoted-expressions */
} }
private _handleActionChanged(ev): void { private _handleActionChanged(ev): void {

View File

@ -5828,10 +5828,58 @@
}, },
"fix_issue": { "fix_issue": {
"fix": "Fix issue", "fix": "Fix issue",
"no_support": {
"title": "Fix issue",
"info_text_1": "Fixing this issue is not supported yet."
},
"no_state": {
"title": "Entity has no state",
"info_text_1": "This entity has no state at the moment, if this is an orphaned entity, you may want to delete the long term statistics of it from your database.",
"info_text_2": "Do you want to permanently delete the long term statistics of {statistic_id} from your database?"
},
"entity_not_recorded": {
"title": "Entity not recorded",
"info_text_1": "State changes of this entity are not recorded, therefore, we cannot track long term statistics for it.",
"info_text_2": "You probably excluded this entity, or have just included some entities.",
"info_text_3_link": "See the recorder documentation for more information."
},
"entity_no_longer_recorded": {
"title": "Entity no longer recorded",
"info_text_1": "We have generated statistics for this entity in the past, but state changes of this entity are no longer recorded, therefore, we cannot track long term statistics for it anymore.",
"info_text_2": "You probably excluded this entity, or have just included some entities.",
"info_text_3_link": "See the recorder documentation for more information."
},
"unsupported_state_class": {
"title": "Unsupported state class",
"info_text_1": "The state class of this entity, {state_class} is not supported.",
"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_4": "If you have set this 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_5": "If the state class has permanently changed, 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?"
},
"units_changed": { "units_changed": {
"title": "The unit of this entity 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.", "update": "Update the unit of the historic statistic values from ''{metadata_unit}'' to ''{state_unit}'', without converting.",
"clear": "Delete all old statistic data for this entity" "clear": "Delete all old statistic data for this entity",
"how_to_fix": "How do you want to fix this issue?",
"info_text_1": "The unit of this entity changed to ''{current_unit}'' which can't be converted to the previously stored unit, ''{previous_unit}''.",
"info_text_2": "If the historic statistic values have a wrong unit, you can update the units of the old values. The values will not be updated.",
"info_text_3": "Otherwise you can choose to delete all historic statistic values, and start over."
},
"adjust_sum": {
"title": "Adjust a statistic",
"no_statistics_found": "No statistics found for this period.",
"info_text_1": "Sometimes the statistics end up being incorrect for a specific point in time. This can mess up your beautiful graphs! Select a time below to find the bad moment and adjust the data.",
"pick_a_time": "Pick a time",
"statistic": "Statistic:",
"start": "Start",
"end": "End",
"new_value": "New value",
"adjust": "Adjust",
"sum_adjusted": "Statistic sum adjusted",
"error_sum_adjusted": "Error adjusting sum: {message}"
} }
}, },
"adjust_sum": "Adjust sum", "adjust_sum": "Adjust sum",