mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-24 21:37:21 +00:00
Use name from metadata in statistics card (#13451)
* Use name from metadata in statistics card * Refactor to use getStatisticLabel
This commit is contained in:
parent
80e7993923
commit
d64c81a123
@ -15,13 +15,13 @@ import {
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { getGraphColorByIndex } from "../../common/color/colors";
|
||||
import { isComponentLoaded } from "../../common/config/is_component_loaded";
|
||||
import { computeStateName } from "../../common/entity/compute_state_name";
|
||||
import {
|
||||
formatNumber,
|
||||
numberFormatToLocale,
|
||||
} from "../../common/number/format_number";
|
||||
import {
|
||||
getStatisticIds,
|
||||
getStatisticLabel,
|
||||
Statistics,
|
||||
statisticsHaveType,
|
||||
StatisticsMetaData,
|
||||
@ -233,19 +233,17 @@ class StatisticsChart extends LitElement {
|
||||
const names = this.names || {};
|
||||
statisticsData.forEach((stats) => {
|
||||
const firstStat = stats[0];
|
||||
let name = names[firstStat.statistic_id];
|
||||
if (!name) {
|
||||
const entityState = this.hass.states[firstStat.statistic_id];
|
||||
if (entityState) {
|
||||
name = computeStateName(entityState);
|
||||
} else {
|
||||
name = firstStat.statistic_id;
|
||||
}
|
||||
}
|
||||
|
||||
const meta = this.statisticIds!.find(
|
||||
(stat) => stat.statistic_id === firstStat.statistic_id
|
||||
);
|
||||
let name = names[firstStat.statistic_id];
|
||||
if (!name) {
|
||||
const tmp: Record<string, StatisticsMetaData> = {};
|
||||
if (meta) {
|
||||
tmp[firstStat.statistic_id] = meta;
|
||||
}
|
||||
name = getStatisticLabel(this.hass, firstStat.statistic_id, tmp);
|
||||
}
|
||||
|
||||
if (!this.unit) {
|
||||
if (unit === undefined) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user