mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-05 16:36:38 +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 { customElement, property, state } from "lit/decorators";
|
||||||
import { getGraphColorByIndex } from "../../common/color/colors";
|
import { getGraphColorByIndex } from "../../common/color/colors";
|
||||||
import { isComponentLoaded } from "../../common/config/is_component_loaded";
|
import { isComponentLoaded } from "../../common/config/is_component_loaded";
|
||||||
import { computeStateName } from "../../common/entity/compute_state_name";
|
|
||||||
import {
|
import {
|
||||||
formatNumber,
|
formatNumber,
|
||||||
numberFormatToLocale,
|
numberFormatToLocale,
|
||||||
} from "../../common/number/format_number";
|
} from "../../common/number/format_number";
|
||||||
import {
|
import {
|
||||||
getStatisticIds,
|
getStatisticIds,
|
||||||
|
getStatisticLabel,
|
||||||
Statistics,
|
Statistics,
|
||||||
statisticsHaveType,
|
statisticsHaveType,
|
||||||
StatisticsMetaData,
|
StatisticsMetaData,
|
||||||
@ -233,19 +233,17 @@ class StatisticsChart extends LitElement {
|
|||||||
const names = this.names || {};
|
const names = this.names || {};
|
||||||
statisticsData.forEach((stats) => {
|
statisticsData.forEach((stats) => {
|
||||||
const firstStat = stats[0];
|
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(
|
const meta = this.statisticIds!.find(
|
||||||
(stat) => stat.statistic_id === firstStat.statistic_id
|
(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 (!this.unit) {
|
||||||
if (unit === undefined) {
|
if (unit === undefined) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user