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