From 30d6c5eaf3a6480d71b03362efc14b0849208de5 Mon Sep 17 00:00:00 2001 From: Philip Allgaier Date: Tue, 15 Jun 2021 19:54:18 +0200 Subject: [PATCH] Gracefully handle logbook retrieval errors (#9377) --- src/dialogs/more-info/ha-more-info-logbook.ts | 40 +++++++++++++------ src/panels/logbook/ha-panel-logbook.ts | 35 ++++++++++------ src/panels/lovelace/cards/hui-logbook-card.ts | 37 ++++++++++++----- src/translations/en.json | 1 + 4 files changed, 78 insertions(+), 35 deletions(-) diff --git a/src/dialogs/more-info/ha-more-info-logbook.ts b/src/dialogs/more-info/ha-more-info-logbook.ts index 08ddc48734..90d01e75a9 100644 --- a/src/dialogs/more-info/ha-more-info-logbook.ts +++ b/src/dialogs/more-info/ha-more-info-logbook.ts @@ -29,6 +29,8 @@ export class MoreInfoLogbook extends LitElement { private _fetchUserPromise?: Promise; + private _error?: string; + private _throttleGetLogbookEntries = throttle(() => { this._getLogBookData(); }, 10000); @@ -45,7 +47,13 @@ export class MoreInfoLogbook extends LitElement { return html` ${isComponentLoaded(this.hass, "logbook") - ? !this._logbookEntries + ? this._error + ? html`
+ ${`${this.hass.localize( + "ui.components.logbook.retrieval_error" + )}: ${this._error}`} +
` + : !this._logbookEntries ? html` ; + private _error?: string; + private _throttleGetLogbookEntries = throttle(() => { this._getLogBookData(); }, 10000); @@ -187,7 +189,15 @@ export class HuiLogbookCard extends LitElement implements LovelaceCard { class=${classMap({ "no-header": !this._config!.title })} >
- ${!this._logbookEntries + ${this._error + ? html` +
+ ${`${this.hass.localize( + "ui.components.logbook.retrieval_error" + )}: ${this._error}`} +
+ ` + : !this._logbookEntries ? html` entity.entity).toString(), - true - ), - this._fetchUserPromise, - ]); + try { + newEntries = await Promise.all([ + getLogbookData( + this.hass, + lastDate.toISOString(), + now.toISOString(), + this._configEntities!.map((entity) => entity.entity).toString(), + true + ), + this._fetchUserPromise, + ]); + } catch (err) { + this._error = err.message; + } const logbookEntries = this._logbookEntries ? [...newEntries, ...this._logbookEntries] diff --git a/src/translations/en.json b/src/translations/en.json index 31d829f9e2..030742b168 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -304,6 +304,7 @@ "by": "by", "by_service": "by service", "show_trace": "Show trace", + "retrieval_error": "Error during logbook entry retrieval", "messages": { "was_away": "was detected away", "was_at_state": "was detected at {state}",