Skip to content
Merged
Changes from 1 commit
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
23 changes: 19 additions & 4 deletions src/panels/lovelace/header-footer/hui-graph-header-footer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { LovelaceHeaderFooter, LovelaceHeaderFooterEditor } from "../types";
import { GraphHeaderFooterConfig } from "./types";

const MINUTE = 60000;
const DAY = 86400000;
const HOUR = MINUTE * 60;

@customElement("hui-graph-header-footer")
export class HuiGraphHeaderFooter extends LitElement
Expand Down Expand Up @@ -162,10 +162,25 @@ export class HuiGraphHeaderFooter extends LitElement
: this._date;

if (this._stateHistory!.length) {
this._stateHistory = this._stateHistory!.filter(
(entity) =>
endTime.getTime() - new Date(entity.last_changed).getTime() <= DAY
const inHoursToShow: HassEntity[] = [];
const outHoursToShow: HassEntity[] = [];
// Split into inside and outside of "hours to show".
this._stateHistory!.forEach((entity) =>
(endTime.getTime() - new Date(entity.last_changed).getTime() <=
this._config!.hours_to_show! * HOUR
? inHoursToShow
: outHoursToShow
).push(entity)
);
this._stateHistory = [];
Comment thread
spacegaier marked this conversation as resolved.
Outdated

if (outHoursToShow.length) {
// If we have values that are now outside of "hours to show", re-add the last entry. This could e.g. be
// the "initial state" from the history backend. Without it, it would look like there is no history data
// at the start at all in the database = graph would start suddenly instead of on the left side of the card.
this._stateHistory.push(outHoursToShow[outHoursToShow.length - 1]);
Comment thread
spacegaier marked this conversation as resolved.
Outdated
}
this._stateHistory = this._stateHistory.concat(inHoursToShow);
Comment thread
spacegaier marked this conversation as resolved.
Outdated
}

const stateHistory = await fetchRecent(
Expand Down