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

This commit is contained in:
Philip Allgaier 2021-11-22 10:56:40 +01:00 committed by GitHub
parent 4719636176
commit 3c67fc96b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 6 deletions

View File

@ -1,3 +1,4 @@
import { startOfYesterday } from "date-fns";
import { css, html, LitElement, PropertyValues, TemplateResult } from "lit"; import { css, html, LitElement, PropertyValues, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { isComponentLoaded } from "../../common/config/is_component_loaded"; import { isComponentLoaded } from "../../common/config/is_component_loaded";
@ -22,6 +23,8 @@ export class MoreInfoHistory extends LitElement {
@state() private _stateHistory?: HistoryResult; @state() private _stateHistory?: HistoryResult;
private _showMoreHref = "";
private _throttleGetStateHistory = throttle(() => { private _throttleGetStateHistory = throttle(() => {
this._getStateHistory(); this._getStateHistory();
}, 10000); }, 10000);
@ -31,14 +34,12 @@ export class MoreInfoHistory extends LitElement {
return html``; return html``;
} }
const href = "/history?entity_id=" + this.entityId;
return html`${isComponentLoaded(this.hass, "history") return html`${isComponentLoaded(this.hass, "history")
? html` <div class="header"> ? html` <div class="header">
<div class="title"> <div class="title">
${this.hass.localize("ui.dialogs.more_info_control.history")} ${this.hass.localize("ui.dialogs.more_info_control.history")}
</div> </div>
<a href=${href} @click=${this._close} <a href=${this._showMoreHref} @click=${this._close}
>${this.hass.localize( >${this.hass.localize(
"ui.dialogs.more_info_control.show_more" "ui.dialogs.more_info_control.show_more"
)}</a )}</a
@ -63,6 +64,10 @@ export class MoreInfoHistory extends LitElement {
return; return;
} }
this._showMoreHref = `/history?entity_id=${
this.entityId
}&start_date=${startOfYesterday().toISOString()}`;
this._throttleGetStateHistory(); this._throttleGetStateHistory();
return; return;
} }

View File

@ -1,3 +1,4 @@
import { startOfYesterday } from "date-fns";
import { css, html, LitElement, PropertyValues, TemplateResult } from "lit"; import { css, html, LitElement, PropertyValues, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { isComponentLoaded } from "../../common/config/is_component_loaded"; import { isComponentLoaded } from "../../common/config/is_component_loaded";
@ -30,6 +31,8 @@ export class MoreInfoLogbook extends LitElement {
private _error?: string; private _error?: string;
private _showMoreHref = "";
private _throttleGetLogbookEntries = throttle(() => { private _throttleGetLogbookEntries = throttle(() => {
this._getLogBookData(); this._getLogBookData();
}, 10000); }, 10000);
@ -44,8 +47,6 @@ export class MoreInfoLogbook extends LitElement {
return html``; return html``;
} }
const href = "/logbook?entity_id=" + this.entityId;
return html` return html`
${isComponentLoaded(this.hass, "logbook") ${isComponentLoaded(this.hass, "logbook")
? this._error ? this._error
@ -67,7 +68,7 @@ export class MoreInfoLogbook extends LitElement {
<div class="title"> <div class="title">
${this.hass.localize("ui.dialogs.more_info_control.logbook")} ${this.hass.localize("ui.dialogs.more_info_control.logbook")}
</div> </div>
<a href=${href} @click=${this._close} <a href=${this._showMoreHref} @click=${this._close}
>${this.hass.localize( >${this.hass.localize(
"ui.dialogs.more_info_control.show_more" "ui.dialogs.more_info_control.show_more"
)}</a )}</a
@ -106,6 +107,10 @@ export class MoreInfoLogbook extends LitElement {
return; return;
} }
this._showMoreHref = `/logbook?entity_id=${
this.entityId
}&start_date=${startOfYesterday().toISOString()}`;
this._throttleGetLogbookEntries(); this._throttleGetLogbookEntries();
return; return;
} }

View File

@ -139,6 +139,11 @@ class HaPanelHistory extends LitElement {
}; };
this._entityId = extractSearchParam("entity_id") ?? ""; this._entityId = extractSearchParam("entity_id") ?? "";
const startDate = extractSearchParam("start_date");
if (startDate) {
this._startDate = new Date(startDate);
}
} }
protected updated(changedProps: PropertyValues) { protected updated(changedProps: PropertyValues) {

View File

@ -161,6 +161,11 @@ export class HaPanelLogbook extends LitElement {
}; };
this._entityId = extractSearchParam("entity_id") ?? ""; this._entityId = extractSearchParam("entity_id") ?? "";
const startDate = extractSearchParam("start_date");
if (startDate) {
this._startDate = new Date(startDate);
}
} }
protected updated(changedProps: PropertyValues<this>) { protected updated(changedProps: PropertyValues<this>) {