Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/panels/lovelace/cards/energy/common/energy-chart-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ import { formatTime } from "../../../../../common/datetime/format_time";
import type { ECOption } from "../../../../../resources/echarts/echarts";
import { filterXSS } from "../../../../../common/util/xss";

export function getSuggestedMax(dayDifference: number, end: Date): number {
export function getSuggestedMax(
dayDifference: number,
end: Date,
detailedDailyData = false
): number {
let suggestedMax = new Date(end);

// Sometimes around DST we get a time of 0:59 instead of 23:59 as expected.
Expand All @@ -40,7 +44,9 @@ export function getSuggestedMax(dayDifference: number, end: Date): number {
suggestedMax = subHours(suggestedMax, 1);
}

suggestedMax.setMinutes(0, 0, 0);
if (!detailedDailyData) {
suggestedMax.setMinutes(0, 0, 0);
}
if (dayDifference > 35) {
suggestedMax.setDate(1);
}
Expand Down Expand Up @@ -77,7 +83,8 @@ export function getCommonOptions(
unit?: string,
compareStart?: Date,
compareEnd?: Date,
formatTotal?: (total: number) => string
formatTotal?: (total: number) => string,
detailedDailyData = false
): ECOption {
const dayDifference = differenceInDays(end, start);

Expand All @@ -89,7 +96,7 @@ export function getCommonOptions(
xAxis: {
type: "time",
min: start,
max: getSuggestedMax(dayDifference, end),
max: getSuggestedMax(dayDifference, end, detailedDailyData),
},
yAxis: {
type: "value",
Expand Down
15 changes: 10 additions & 5 deletions src/panels/lovelace/cards/energy/hui-power-sources-graph-card.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { endOfToday, isToday, startOfToday } from "date-fns";
import { endOfToday, isSameDay, isToday, startOfToday } from "date-fns";
import type { HassConfig, UnsubscribeFunc } from "home-assistant-js-websocket";
import type { PropertyValues } from "lit";
import { css, html, LitElement, nothing } from "lit";
Expand Down Expand Up @@ -132,7 +132,9 @@ export class HuiPowerSourcesGraphCard
config,
"kW",
compareStart,
compareEnd
compareEnd,
undefined,
true
),
legend: {
show: this._config?.show_legend !== false,
Expand Down Expand Up @@ -210,9 +212,12 @@ export class HuiPowerSourcesGraphCard
const { positive, negative } = this._processData(
statIds[key].stats.map((id: string) => {
const stats = energyData.stats[id] ?? [];
const currentState = getPowerFromState(this.hass.states[id]);
if (currentState !== undefined) {
stats.push({ start: now, end: now, mean: currentState });
if (isSameDay(now, this._start) && isSameDay(now, this._end)) {
// Append current state if we are showing today
const currentState = getPowerFromState(this.hass.states[id]);
if (currentState !== undefined) {
stats.push({ start: now, end: now, mean: currentState });
}
}
return stats;
})
Expand Down
Loading