mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-26 22:37:21 +00:00
Refactor getStatisticLabel (#13486)
This commit is contained in:
parent
a8833a5ec1
commit
5d1536030a
@ -238,11 +238,7 @@ class StatisticsChart extends LitElement {
|
|||||||
);
|
);
|
||||||
let name = names[firstStat.statistic_id];
|
let name = names[firstStat.statistic_id];
|
||||||
if (!name) {
|
if (!name) {
|
||||||
const tmp: Record<string, StatisticsMetaData> = {};
|
name = getStatisticLabel(this.hass, firstStat.statistic_id, meta);
|
||||||
if (meta) {
|
|
||||||
tmp[firstStat.statistic_id] = meta;
|
|
||||||
}
|
|
||||||
name = getStatisticLabel(this.hass, firstStat.statistic_id, tmp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.unit) {
|
if (!this.unit) {
|
||||||
|
@ -569,12 +569,11 @@ export const adjustStatisticsSum = (
|
|||||||
export const getStatisticLabel = (
|
export const getStatisticLabel = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
statisticsId: string,
|
statisticsId: string,
|
||||||
statisticsMetaData: Record<string, StatisticsMetaData> | undefined
|
statisticsMetaData: StatisticsMetaData | undefined
|
||||||
): string => {
|
): string => {
|
||||||
const entity = hass.states[statisticsId];
|
const entity = hass.states[statisticsId];
|
||||||
if (entity) {
|
if (entity) {
|
||||||
return computeStateName(entity);
|
return computeStateName(entity);
|
||||||
}
|
}
|
||||||
const statisticMetaData = statisticsMetaData?.[statisticsId];
|
return statisticsMetaData?.name || statisticsId;
|
||||||
return statisticMetaData?.name || statisticsId;
|
|
||||||
};
|
};
|
||||||
|
@ -104,14 +104,14 @@ export class EnergyBatterySettings extends LitElement {
|
|||||||
>${getStatisticLabel(
|
>${getStatisticLabel(
|
||||||
this.hass,
|
this.hass,
|
||||||
source.stat_energy_from,
|
source.stat_energy_from,
|
||||||
this.statsMetadata
|
this.statsMetadata[source.stat_energy_from]
|
||||||
)}</span
|
)}</span
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
>${getStatisticLabel(
|
>${getStatisticLabel(
|
||||||
this.hass,
|
this.hass,
|
||||||
source.stat_energy_to,
|
source.stat_energy_to,
|
||||||
this.statsMetadata
|
this.statsMetadata[source.stat_energy_to]
|
||||||
)}</span
|
)}</span
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
@ -90,7 +90,7 @@ export class EnergyDeviceSettings extends LitElement {
|
|||||||
>${getStatisticLabel(
|
>${getStatisticLabel(
|
||||||
this.hass,
|
this.hass,
|
||||||
device.stat_consumption,
|
device.stat_consumption,
|
||||||
this.statsMetadata
|
this.statsMetadata[device.stat_consumption]
|
||||||
)}</span
|
)}</span
|
||||||
>
|
>
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
|
@ -98,7 +98,7 @@ export class EnergyGasSettings extends LitElement {
|
|||||||
>${getStatisticLabel(
|
>${getStatisticLabel(
|
||||||
this.hass,
|
this.hass,
|
||||||
source.stat_energy_from,
|
source.stat_energy_from,
|
||||||
this.statsMetadata
|
this.statsMetadata[source.stat_energy_from]
|
||||||
)}</span
|
)}</span
|
||||||
>
|
>
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
|
@ -136,7 +136,7 @@ export class EnergyGridSettings extends LitElement {
|
|||||||
>${getStatisticLabel(
|
>${getStatisticLabel(
|
||||||
this.hass,
|
this.hass,
|
||||||
flow.stat_energy_from,
|
flow.stat_energy_from,
|
||||||
this.statsMetadata
|
this.statsMetadata[flow.stat_energy_from]
|
||||||
)}</span
|
)}</span
|
||||||
>
|
>
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
@ -183,7 +183,7 @@ export class EnergyGridSettings extends LitElement {
|
|||||||
>${getStatisticLabel(
|
>${getStatisticLabel(
|
||||||
this.hass,
|
this.hass,
|
||||||
flow.stat_energy_to,
|
flow.stat_energy_to,
|
||||||
this.statsMetadata
|
this.statsMetadata[flow.stat_energy_to]
|
||||||
)}</span
|
)}</span
|
||||||
>
|
>
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
|
@ -106,7 +106,7 @@ export class EnergySolarSettings extends LitElement {
|
|||||||
>${getStatisticLabel(
|
>${getStatisticLabel(
|
||||||
this.hass,
|
this.hass,
|
||||||
source.stat_energy_from,
|
source.stat_energy_from,
|
||||||
this.statsMetadata
|
this.statsMetadata[source.stat_energy_from]
|
||||||
)}</span
|
)}</span
|
||||||
>
|
>
|
||||||
${this.info
|
${this.info
|
||||||
|
@ -116,7 +116,7 @@ export class HuiEnergyDevicesGraphCard
|
|||||||
return getStatisticLabel(
|
return getStatisticLabel(
|
||||||
this.hass,
|
this.hass,
|
||||||
statisticId as any,
|
statisticId as any,
|
||||||
this._data?.statsMetadata
|
this._data?.statsMetadata[statisticId]
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -138,7 +138,7 @@ export class HuiEnergyDevicesGraphCard
|
|||||||
return getStatisticLabel(
|
return getStatisticLabel(
|
||||||
this.hass,
|
this.hass,
|
||||||
statisticId,
|
statisticId,
|
||||||
this._data?.statsMetadata
|
this._data?.statsMetadata[statisticId]
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
label: (context) =>
|
label: (context) =>
|
||||||
|
@ -382,7 +382,7 @@ export class HuiEnergyGasGraphCard
|
|||||||
label: getStatisticLabel(
|
label: getStatisticLabel(
|
||||||
this.hass,
|
this.hass,
|
||||||
source.stat_energy_from,
|
source.stat_energy_from,
|
||||||
statisticsMetaData
|
statisticsMetaData[source.stat_energy_from]
|
||||||
),
|
),
|
||||||
borderColor: compare ? borderColor + "7F" : borderColor,
|
borderColor: compare ? borderColor + "7F" : borderColor,
|
||||||
backgroundColor: compare ? borderColor + "32" : borderColor + "7F",
|
backgroundColor: compare ? borderColor + "32" : borderColor + "7F",
|
||||||
|
@ -405,7 +405,7 @@ export class HuiEnergySolarGraphCard
|
|||||||
name: getStatisticLabel(
|
name: getStatisticLabel(
|
||||||
this.hass,
|
this.hass,
|
||||||
source.stat_energy_from,
|
source.stat_energy_from,
|
||||||
statisticsMetaData
|
statisticsMetaData[source.stat_energy_from]
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
@ -483,7 +483,7 @@ export class HuiEnergySolarGraphCard
|
|||||||
name: getStatisticLabel(
|
name: getStatisticLabel(
|
||||||
this.hass,
|
this.hass,
|
||||||
source.stat_energy_from,
|
source.stat_energy_from,
|
||||||
statisticsMetaData
|
statisticsMetaData[source.stat_energy_from]
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
@ -239,7 +239,7 @@ export class HuiEnergySourcesTableCard
|
|||||||
${getStatisticLabel(
|
${getStatisticLabel(
|
||||||
this.hass,
|
this.hass,
|
||||||
source.stat_energy_from,
|
source.stat_energy_from,
|
||||||
this._data?.statsMetadata
|
this._data?.statsMetadata[source.stat_energy_from]
|
||||||
)}
|
)}
|
||||||
</th>
|
</th>
|
||||||
${compare
|
${compare
|
||||||
@ -347,7 +347,7 @@ export class HuiEnergySourcesTableCard
|
|||||||
${getStatisticLabel(
|
${getStatisticLabel(
|
||||||
this.hass,
|
this.hass,
|
||||||
source.stat_energy_from,
|
source.stat_energy_from,
|
||||||
this._data?.statsMetadata
|
this._data?.statsMetadata[source.stat_energy_from]
|
||||||
)}
|
)}
|
||||||
</th>
|
</th>
|
||||||
${compare
|
${compare
|
||||||
@ -384,7 +384,7 @@ export class HuiEnergySourcesTableCard
|
|||||||
${getStatisticLabel(
|
${getStatisticLabel(
|
||||||
this.hass,
|
this.hass,
|
||||||
source.stat_energy_to,
|
source.stat_energy_to,
|
||||||
this._data?.statsMetadata
|
this._data?.statsMetadata[source.stat_energy_to]
|
||||||
)}
|
)}
|
||||||
</th>
|
</th>
|
||||||
${compare
|
${compare
|
||||||
@ -505,7 +505,7 @@ export class HuiEnergySourcesTableCard
|
|||||||
${getStatisticLabel(
|
${getStatisticLabel(
|
||||||
this.hass,
|
this.hass,
|
||||||
flow.stat_energy_from,
|
flow.stat_energy_from,
|
||||||
this._data?.statsMetadata
|
this._data?.statsMetadata[flow.stat_energy_from]
|
||||||
)}
|
)}
|
||||||
</th>
|
</th>
|
||||||
${compare
|
${compare
|
||||||
@ -610,7 +610,7 @@ export class HuiEnergySourcesTableCard
|
|||||||
${getStatisticLabel(
|
${getStatisticLabel(
|
||||||
this.hass,
|
this.hass,
|
||||||
flow.stat_energy_to,
|
flow.stat_energy_to,
|
||||||
this._data?.statsMetadata
|
this._data?.statsMetadata[flow.stat_energy_to]
|
||||||
)}
|
)}
|
||||||
</th>
|
</th>
|
||||||
${compare
|
${compare
|
||||||
@ -763,7 +763,7 @@ export class HuiEnergySourcesTableCard
|
|||||||
${getStatisticLabel(
|
${getStatisticLabel(
|
||||||
this.hass,
|
this.hass,
|
||||||
source.stat_energy_from,
|
source.stat_energy_from,
|
||||||
this._data?.statsMetadata
|
this._data?.statsMetadata[source.stat_energy_from]
|
||||||
)}
|
)}
|
||||||
</th>
|
</th>
|
||||||
${compare
|
${compare
|
||||||
|
@ -620,7 +620,11 @@ export class HuiEnergyUsageGraphCard
|
|||||||
label:
|
label:
|
||||||
type in labels
|
type in labels
|
||||||
? labels[type]
|
? labels[type]
|
||||||
: getStatisticLabel(this.hass, statId, statisticsMetaData),
|
: getStatisticLabel(
|
||||||
|
this.hass,
|
||||||
|
statId,
|
||||||
|
statisticsMetaData[statId]
|
||||||
|
),
|
||||||
order:
|
order:
|
||||||
type === "used_solar"
|
type === "used_solar"
|
||||||
? 1
|
? 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user