mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 15:26:36 +00:00
Fix labels device energy graph (#10134)
* Fix labels device energy graph * prettier
This commit is contained in:
parent
792a736e48
commit
8a4097a366
@ -3,6 +3,7 @@ import {
|
||||
ChartDataset,
|
||||
ChartOptions,
|
||||
ParsedDataType,
|
||||
ScatterDataPoint,
|
||||
} from "chart.js";
|
||||
import { getRelativePosition } from "chart.js/helpers";
|
||||
import { addHours } from "date-fns";
|
||||
@ -21,11 +22,7 @@ import {
|
||||
import "../../../../components/chart/ha-chart-base";
|
||||
import type HaChartBase from "../../../../components/chart/ha-chart-base";
|
||||
import "../../../../components/ha-card";
|
||||
import {
|
||||
DeviceConsumptionEnergyPreference,
|
||||
EnergyData,
|
||||
getEnergyDataCollection,
|
||||
} from "../../../../data/energy";
|
||||
import { EnergyData, getEnergyDataCollection } from "../../../../data/energy";
|
||||
import {
|
||||
calculateStatisticSumGrowth,
|
||||
fetchStatistics,
|
||||
@ -52,8 +49,6 @@ export class HuiEnergyDevicesGraphCard
|
||||
|
||||
@query("ha-chart-base") private _chart?: HaChartBase;
|
||||
|
||||
private _deviceConsumptionPrefs: DeviceConsumptionEnergyPreference[] = [];
|
||||
|
||||
public hassSubscribe(): UnsubscribeFunc[] {
|
||||
return [
|
||||
getEnergyDataCollection(this.hass, {
|
||||
@ -110,11 +105,11 @@ export class HuiEnergyDevicesGraphCard
|
||||
ticks: {
|
||||
autoSkip: false,
|
||||
callback: (index) => {
|
||||
const devicePref = this._deviceConsumptionPrefs[index];
|
||||
const entity = this.hass.states[devicePref.stat_consumption];
|
||||
return entity
|
||||
? computeStateName(entity)
|
||||
: devicePref.stat_consumption;
|
||||
const entityId = (
|
||||
this._chartData.datasets[0].data[index] as ScatterDataPoint
|
||||
).y;
|
||||
const entity = this.hass.states[entityId];
|
||||
return entity ? computeStateName(entity) : entityId;
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -160,8 +155,6 @@ export class HuiEnergyDevicesGraphCard
|
||||
);
|
||||
|
||||
private async _getStatistics(energyData: EnergyData): Promise<void> {
|
||||
this._deviceConsumptionPrefs = energyData.prefs.device_consumption;
|
||||
|
||||
this._data = await fetchStatistics(
|
||||
this.hass,
|
||||
addHours(energyData.start, -1),
|
||||
|
Loading…
x
Reference in New Issue
Block a user