Skip to content

Commit

Permalink
Add translations for the developer tools statistic issues (#18646)
Browse files Browse the repository at this point in the history
  • Loading branch information
silamon authored Nov 16, 2023
1 parent 3addfc3 commit fb95de1
Show file tree
Hide file tree
Showing 4 changed files with 230 additions and 89 deletions.
138 changes: 91 additions & 47 deletions src/panels/developer-tools/statistics/developer-tools-statistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { HomeAssistant } from "../../../types";
import { showStatisticsAdjustSumDialog } from "./show-dialog-statistics-adjust-sum";
import { showFixStatisticsUnitsChangedDialog } from "./show-dialog-statistics-fix-units-changed";
import { computeRTLDirection } from "../../../common/util/compute_rtl";
import { documentationUrl } from "../../../util/documentation-url";

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

/* eslint-disable lit/no-template-arrow */

@customElement("dialog-statistics-adjust-sum")
export class DialogStatisticsFixUnsupportedUnitMetadata extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
Expand Down Expand Up @@ -111,7 +109,9 @@ export class DialogStatisticsFixUnsupportedUnitMetadata extends LitElement {
scrimClickAction
escapeKeyAction
@closed=${this.closeDialog}
heading="Adjust a statistic"
.heading=${this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.adjust_sum.title"
)}
>
${content}
</ha-dialog>
Expand All @@ -133,7 +133,11 @@ export class DialogStatisticsFixUnsupportedUnitMetadata extends LitElement {
if (!this._stats5min || !this._statsHour) {
stats = html`<ha-circular-progress active></ha-circular-progress>`;
} 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 {
const data =
this._stats5min.length >= 1 ? this._stats5min : this._statsHour;
Expand All @@ -150,11 +154,8 @@ export class DialogStatisticsFixUnsupportedUnitMetadata extends LitElement {
<mwc-list-item
twoline
hasMeta
@click=${() => {
this._chosenStat = stat;
this._origAmount = growth;
this._amount = growth;
}}
.stat=${stat}
@click=${this._setChosenStatistic}
>
<span>${growth} ${unit}</span>
<span slot="secondary">
Expand All @@ -173,15 +174,22 @@ export class DialogStatisticsFixUnsupportedUnitMetadata extends LitElement {

return html`
<div class="text-content">
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.
${this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.adjust_sum.info_text_1"
)}
</div>
<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>
<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}
.selector=${this._dateTimeSelector}
.value=${this._moment}
Expand All @@ -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) {
this._moment = ev.detail.value;
this._fetchStats();
Expand All @@ -209,11 +230,20 @@ export class DialogStatisticsFixUnsupportedUnitMetadata extends LitElement {
);
return html`
<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 class="table-row">
<span>Start</span>
<span
>${this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.adjust_sum.start"
)}</span
>
<span
>${formatDateTime(
new Date(this._chosenStat!.start),
Expand All @@ -224,7 +254,11 @@ export class DialogStatisticsFixUnsupportedUnitMetadata extends LitElement {
</div>
<div class="table-row">
<span>End</span>
<span
>${this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.adjust_sum.end"
)}</span
>
<span
>${formatDateTime(
new Date(this._chosenStat!.end),
Expand All @@ -235,35 +269,37 @@ export class DialogStatisticsFixUnsupportedUnitMetadata extends LitElement {
</div>
<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}
.selector=${this._amountSelector(unit || undefined)}
.value=${this._amount}
.disabled=${this._busy}
@value-changed=${(ev) => {
this._amount = ev.detail.value;
}}
@value-changed=${this._amountChanged}
></ha-selector-number>
<mwc-button
slot="primaryAction"
label="Adjust"
.label=${this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.adjust_sum.adjust"
)}
.disabled=${this._busy}
@click=${() => {
this._fixIssue();
}}
@click=${this._fixIssue}
></mwc-button>
<mwc-button
slot="secondaryAction"
.label=${this.hass.localize("ui.common.back")}
.disabled=${this._busy}
@click=${() => {
this._chosenStat = undefined;
}}
@click=${this._clearChosenStatistic}
></mwc-button>
`;
}

private _amountChanged(ev) {
this._amount = ev.detail.value;
}

private async _fetchStats(): Promise<void> {
this._stats5min = undefined;
this._statsHour = undefined;
Expand Down Expand Up @@ -331,12 +367,17 @@ export class DialogStatisticsFixUnsupportedUnitMetadata extends LitElement {
} catch (err: any) {
this._busy = false;
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;
}
showToast(this, {
message: "Statistic sum adjusted",
message: this.hass.localize(
"ui.panel.developer-tools.tabs.statistics.fix_issue.adjust_sum.sum_adjusted"
),
});
this.closeDialog();
}
Expand Down
Loading

0 comments on commit fb95de1

Please sign in to comment.