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 { customElement, property, state } from "lit/decorators";
import { isComponentLoaded } from "../../common/config/is_component_loaded";
@ -22,6 +23,8 @@ export class MoreInfoHistory extends LitElement {
@state() private _stateHistory?: HistoryResult;
private _showMoreHref = "";
private _throttleGetStateHistory = throttle(() => {
this._getStateHistory();
}, 10000);
@ -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
@ -63,6 +64,10 @@ export class MoreInfoHistory extends LitElement {
return;
}
this._showMoreHref = `/history?entity_id=${
this.entityId
}&start_date=${startOfYesterday().toISOString()}`;
this._throttleGetStateHistory();
return;
}

View File

@ -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";
@ -30,6 +31,8 @@ export class MoreInfoLogbook extends LitElement {
private _error?: string;
private _showMoreHref = "";
private _throttleGetLogbookEntries = throttle(() => {
this._getLogBookData();
}, 10000);
@ -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
@ -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
@ -106,6 +107,10 @@ export class MoreInfoLogbook extends LitElement {
return;
}
this._showMoreHref = `/logbook?entity_id=${
this.entityId
}&start_date=${startOfYesterday().toISOString()}`;
this._throttleGetLogbookEntries();
return;
}

View File

@ -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) {

View File

@ -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>) {