Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make "Show more" show everything starting from yesterday #10533

Merged
merged 4 commits into from
Nov 22, 2021
Merged
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
11 changes: 8 additions & 3 deletions src/dialogs/more-info/ha-more-info-history.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { startOfYesterday } from "date-fns";
import { css, html, LitElement, PropertyValues, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators";
import { isComponentLoaded } from "../../common/config/is_component_loaded";
Expand All @@ -22,6 +23,8 @@ export class MoreInfoHistory extends LitElement {

@state() private _stateHistory?: HistoryResult;

private _showMoreHref = "";

private _throttleGetStateHistory = throttle(() => {
this._getStateHistory();
}, 10000);
Expand All @@ -31,14 +34,12 @@ export class MoreInfoHistory extends LitElement {
return html``;
}

const href = "/history?entity_id=" + this.entityId;

return html`${isComponentLoaded(this.hass, "history")
? html` <div class="header">
<div class="title">
${this.hass.localize("ui.dialogs.more_info_control.history")}
</div>
<a href=${href} @click=${this._close}
<a href=${this._showMoreHref} @click=${this._close}
>${this.hass.localize(
"ui.dialogs.more_info_control.show_more"
)}</a
Expand All @@ -63,6 +64,10 @@ export class MoreInfoHistory extends LitElement {
return;
}

this._showMoreHref = `/history?entity_id=${
this.entityId
}&start_date=${startOfYesterday().toISOString()}`;

this._throttleGetStateHistory();
return;
}
Expand Down
11 changes: 8 additions & 3 deletions src/dialogs/more-info/ha-more-info-logbook.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { startOfYesterday } from "date-fns";
import { css, html, LitElement, PropertyValues, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators";
import { isComponentLoaded } from "../../common/config/is_component_loaded";
Expand Down Expand Up @@ -30,6 +31,8 @@ export class MoreInfoLogbook extends LitElement {

private _error?: string;

private _showMoreHref = "";

private _throttleGetLogbookEntries = throttle(() => {
this._getLogBookData();
}, 10000);
Expand All @@ -44,8 +47,6 @@ export class MoreInfoLogbook extends LitElement {
return html``;
}

const href = "/logbook?entity_id=" + this.entityId;

return html`
${isComponentLoaded(this.hass, "logbook")
? this._error
Expand All @@ -67,7 +68,7 @@ export class MoreInfoLogbook extends LitElement {
<div class="title">
${this.hass.localize("ui.dialogs.more_info_control.logbook")}
</div>
<a href=${href} @click=${this._close}
<a href=${this._showMoreHref} @click=${this._close}
>${this.hass.localize(
"ui.dialogs.more_info_control.show_more"
)}</a
Expand Down Expand Up @@ -106,6 +107,10 @@ export class MoreInfoLogbook extends LitElement {
return;
}

this._showMoreHref = `/logbook?entity_id=${
this.entityId
}&start_date=${startOfYesterday().toISOString()}`;

this._throttleGetLogbookEntries();
return;
}
Expand Down
5 changes: 5 additions & 0 deletions src/panels/history/ha-panel-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ class HaPanelHistory extends LitElement {
};

this._entityId = extractSearchParam("entity_id") ?? "";

const startDate = extractSearchParam("start_date");
if (startDate) {
this._startDate = new Date(startDate);
}
}

protected updated(changedProps: PropertyValues) {
Expand Down
5 changes: 5 additions & 0 deletions src/panels/logbook/ha-panel-logbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ export class HaPanelLogbook extends LitElement {
};

this._entityId = extractSearchParam("entity_id") ?? "";

const startDate = extractSearchParam("start_date");
if (startDate) {
this._startDate = new Date(startDate);
}
}

protected updated(changedProps: PropertyValues<this>) {
Expand Down