Check if history and logbook are loaded (#6908)

This commit is contained in:
Bram Kragten 2020-09-11 10:17:05 +02:00 committed by GitHub
parent b0508f430e
commit ce8ee569c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 9 deletions

View File

@ -223,7 +223,8 @@ export class MoreInfoDialog extends LitElement {
private _computeShowHistoryComponent(entityId) { private _computeShowHistoryComponent(entityId) {
return ( return (
isComponentLoaded(this.hass, "history") && (isComponentLoaded(this.hass, "history") ||
isComponentLoaded(this.hass, "logbook")) &&
!DOMAINS_MORE_INFO_NO_HISTORY.includes(computeDomain(entityId)) !DOMAINS_MORE_INFO_NO_HISTORY.includes(computeDomain(entityId))
); );
} }

View File

@ -8,6 +8,7 @@ import {
PropertyValues, PropertyValues,
TemplateResult, TemplateResult,
} from "lit-element"; } from "lit-element";
import { isComponentLoaded } from "../../common/config/is_component_loaded";
import { computeStateDomain } from "../../common/entity/compute_state_domain"; import { computeStateDomain } from "../../common/entity/compute_state_domain";
import "../../components/ha-circular-progress"; import "../../components/ha-circular-progress";
import "../../components/state-history-charts"; import "../../components/state-history-charts";
@ -42,13 +43,16 @@ export class MoreInfoHistory extends LitElement {
return html``; return html``;
} }
return html`<state-history-charts return html`${isComponentLoaded(this.hass, "history")
? html`<state-history-charts
up-to-now up-to-now
.hass=${this.hass} .hass=${this.hass}
.historyData=${this._stateHistory} .historyData=${this._stateHistory}
.isLoadingData=${!this._stateHistory} .isLoadingData=${!this._stateHistory}
></state-history-charts> ></state-history-charts>`
${!this._entries : ""}
${isComponentLoaded(this.hass, "logbook")
? !this._entries
? html` ? html`
<ha-circular-progress <ha-circular-progress
active active
@ -69,7 +73,8 @@ export class MoreInfoHistory extends LitElement {
` `
: html`<div class="no-entries"> : html`<div class="no-entries">
${this.hass.localize("ui.components.logbook.entries_not_found")} ${this.hass.localize("ui.components.logbook.entries_not_found")}
</div>`}`; </div>`
: ""} `;
} }
protected firstUpdated(): void { protected firstUpdated(): void {
@ -97,6 +102,9 @@ export class MoreInfoHistory extends LitElement {
} }
private async _getStateHistory(): Promise<void> { private async _getStateHistory(): Promise<void> {
if (!isComponentLoaded(this.hass, "history")) {
return;
}
this._stateHistory = await getRecentWithCache( this._stateHistory = await getRecentWithCache(
this.hass!, this.hass!,
this.entityId, this.entityId,
@ -111,6 +119,9 @@ export class MoreInfoHistory extends LitElement {
} }
private async _getLogBookData() { private async _getLogBookData() {
if (!isComponentLoaded(this.hass, "logbook")) {
return;
}
const yesterday = new Date(new Date().getTime() - 24 * 60 * 60 * 1000); const yesterday = new Date(new Date().getTime() - 24 * 60 * 60 * 1000);
const now = new Date(); const now = new Date();
this._entries = await getLogbookData( this._entries = await getLogbookData(