mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 07:16:39 +00:00
Final energy tweaks (#9694)
This commit is contained in:
parent
32e8c1dc6d
commit
9b33ead8aa
@ -4,6 +4,7 @@ import {
|
|||||||
ChartOptions,
|
ChartOptions,
|
||||||
ParsedDataType,
|
ParsedDataType,
|
||||||
} from "chart.js";
|
} from "chart.js";
|
||||||
|
import { getRelativePosition } from "chart.js/helpers";
|
||||||
import { addHours } from "date-fns";
|
import { addHours } from "date-fns";
|
||||||
import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
@ -11,6 +12,7 @@ import { customElement, property, state } from "lit/decorators";
|
|||||||
import { classMap } from "lit/directives/class-map";
|
import { classMap } from "lit/directives/class-map";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { getColorByIndex } from "../../../../common/color/colors";
|
import { getColorByIndex } from "../../../../common/color/colors";
|
||||||
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
import { computeStateName } from "../../../../common/entity/compute_state_name";
|
import { computeStateName } from "../../../../common/entity/compute_state_name";
|
||||||
import {
|
import {
|
||||||
formatNumber,
|
formatNumber,
|
||||||
@ -120,6 +122,18 @@ export class HuiEnergyDevicesGraphCard
|
|||||||
},
|
},
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
locale: numberFormatToLocale(this.hass.locale),
|
locale: numberFormatToLocale(this.hass.locale),
|
||||||
|
onClick: (e: any) => {
|
||||||
|
const chart = e.chart;
|
||||||
|
const canvasPosition = getRelativePosition(e, chart);
|
||||||
|
|
||||||
|
const index = Math.abs(
|
||||||
|
chart.scales.y.getValueForPixel(canvasPosition.y)
|
||||||
|
);
|
||||||
|
fireEvent(this, "hass-more-info", {
|
||||||
|
// @ts-ignore
|
||||||
|
entityId: this._chartData?.datasets[0]?.data[index]?.entity_id,
|
||||||
|
});
|
||||||
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -162,19 +176,13 @@ export class HuiEnergyDevicesGraphCard
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
for (let idx = 0; idx < energyData.prefs.device_consumption.length; idx++) {
|
energyData.prefs.device_consumption.forEach((device, idx) => {
|
||||||
const device = energyData.prefs.device_consumption[idx];
|
|
||||||
const entity = this.hass.states[device.stat_consumption];
|
const entity = this.hass.states[device.stat_consumption];
|
||||||
const label = entity ? computeStateName(entity) : device.stat_consumption;
|
const label = entity ? computeStateName(entity) : device.stat_consumption;
|
||||||
|
|
||||||
const color = getColorByIndex(idx);
|
|
||||||
|
|
||||||
borderColor.push(color);
|
|
||||||
backgroundColor.push(color + "7F");
|
|
||||||
|
|
||||||
const value =
|
const value =
|
||||||
device.stat_consumption in this._data
|
device.stat_consumption in this._data!
|
||||||
? calculateStatisticSumGrowth(this._data[device.stat_consumption]) ||
|
? calculateStatisticSumGrowth(this._data![device.stat_consumption]) ||
|
||||||
0
|
0
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
@ -182,11 +190,20 @@ export class HuiEnergyDevicesGraphCard
|
|||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
y: label,
|
y: label,
|
||||||
x: value,
|
x: value,
|
||||||
|
entity_id: device.stat_consumption,
|
||||||
|
idx,
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
data.sort((a, b) => b.x - a.x);
|
data.sort((a, b) => b.x - a.x);
|
||||||
|
|
||||||
|
data.forEach((d: any) => {
|
||||||
|
const color = getColorByIndex(d.idx);
|
||||||
|
|
||||||
|
borderColor.push(color);
|
||||||
|
backgroundColor.push(color + "7F");
|
||||||
|
});
|
||||||
|
|
||||||
this._chartData = {
|
this._chartData = {
|
||||||
datasets,
|
datasets,
|
||||||
};
|
};
|
||||||
|
@ -88,10 +88,10 @@ class HuiEnergySolarGaugeCard
|
|||||||
<ha-card>
|
<ha-card>
|
||||||
<ha-svg-icon id="info" .path=${mdiInformation}></ha-svg-icon>
|
<ha-svg-icon id="info" .path=${mdiInformation}></ha-svg-icon>
|
||||||
<paper-tooltip animation-delay="0" for="info" position="left">
|
<paper-tooltip animation-delay="0" for="info" position="left">
|
||||||
This card represents how much of the solar energy was not used by your
|
This card represents how much of the solar energy was used by your
|
||||||
home and was returned to the grid. If you frequently return a lot, try
|
home and was not returned to the grid. If you frequently produce more
|
||||||
to conserve this energy by installing a battery or buying an electric
|
than you consume, try to conserve this energy by installing a battery
|
||||||
car to charge.
|
or buying an electric car to charge.
|
||||||
</paper-tooltip>
|
</paper-tooltip>
|
||||||
${value !== undefined
|
${value !== undefined
|
||||||
? html`<ha-gauge
|
? html`<ha-gauge
|
||||||
|
@ -271,6 +271,9 @@ export class HuiEnergySolarGraphCard
|
|||||||
forecastsData = forecasts![configEntryId]?.wh_hours;
|
forecastsData = forecasts![configEntryId]?.wh_hours;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!forecasts![configEntryId]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Object.entries(forecasts![configEntryId].wh_hours).forEach(
|
Object.entries(forecasts![configEntryId].wh_hours).forEach(
|
||||||
([date, value]) => {
|
([date, value]) => {
|
||||||
if (date in forecastsData!) {
|
if (date in forecastsData!) {
|
||||||
|
@ -352,6 +352,7 @@ export class HuiEnergyUsageGraphCard
|
|||||||
: entity
|
: entity
|
||||||
? computeStateName(entity)
|
? computeStateName(entity)
|
||||||
: statId,
|
: statId,
|
||||||
|
order: type === "used_solar" ? 0 : idx + 1,
|
||||||
borderColor,
|
borderColor,
|
||||||
backgroundColor: hexBlend(borderColor, backgroundColor, 50),
|
backgroundColor: hexBlend(borderColor, backgroundColor, 50),
|
||||||
stack: "stack",
|
stack: "stack",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user