don't use entity name as label in more info stats (#14213)

This commit is contained in:
Bram Kragten 2022-10-27 15:29:22 +02:00 committed by GitHub
parent 4c8e863c0e
commit b3e2beac5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 5 deletions

View File

@ -253,7 +253,7 @@ class StatisticsChart extends LitElement {
const firstStat = stats[0];
const meta = statisticsMetaData?.[firstStat.statistic_id];
let name = names[firstStat.statistic_id];
if (!name) {
if (name === undefined) {
name = getStatisticLabel(this.hass, firstStat.statistic_id, meta);
}
@ -324,10 +324,14 @@ class StatisticsChart extends LitElement {
const band = drawBands && (type === "min" || type === "max");
statTypes.push(type);
statDataSets.push({
label: `${name} (${this.hass.localize(
`ui.components.statistics_charts.statistic_types.${type}`
)})
`,
label: name
? `${name} (${this.hass.localize(
`ui.components.statistics_charts.statistic_types.${type}`
)})
`
: this.hass.localize(
`ui.components.statistics_charts.statistic_types.${type}`
),
fill: drawBands
? type === "min"
? "+1"

View File

@ -36,6 +36,8 @@ export class MoreInfoHistory extends LitElement {
private _showMoreHref = "";
private _statNames?: Record<string, string>;
private _throttleGetStateHistory = throttle(() => {
this._getStateHistory();
}, 10000);
@ -62,6 +64,7 @@ export class MoreInfoHistory extends LitElement {
.isLoadingData=${!this._statistics}
.statisticsData=${this._statistics}
.statTypes=${statTypes}
.names=${this._statNames}
></statistics-chart>`
: html`<state-history-charts
up-to-now
@ -113,6 +116,7 @@ export class MoreInfoHistory extends LitElement {
computeDomain(this.entityId) === "sensor"
) {
const metadata = await getStatisticMetadata(this.hass, [this.entityId]);
this._statNames = { [this.entityId]: "" };
if (metadata.length) {
this._statistics = await fetchStatistics(
this.hass!,