mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-26 02:36:37 +00:00
Gracefully handle logbook retrieval errors (#9377)
This commit is contained in:
parent
6e50d1166a
commit
30d6c5eaf3
@ -29,6 +29,8 @@ export class MoreInfoLogbook extends LitElement {
|
|||||||
|
|
||||||
private _fetchUserPromise?: Promise<void>;
|
private _fetchUserPromise?: Promise<void>;
|
||||||
|
|
||||||
|
private _error?: string;
|
||||||
|
|
||||||
private _throttleGetLogbookEntries = throttle(() => {
|
private _throttleGetLogbookEntries = throttle(() => {
|
||||||
this._getLogBookData();
|
this._getLogBookData();
|
||||||
}, 10000);
|
}, 10000);
|
||||||
@ -45,7 +47,13 @@ export class MoreInfoLogbook extends LitElement {
|
|||||||
|
|
||||||
return html`
|
return html`
|
||||||
${isComponentLoaded(this.hass, "logbook")
|
${isComponentLoaded(this.hass, "logbook")
|
||||||
? !this._logbookEntries
|
? this._error
|
||||||
|
? html`<div class="no-entries">
|
||||||
|
${`${this.hass.localize(
|
||||||
|
"ui.components.logbook.retrieval_error"
|
||||||
|
)}: ${this._error}`}
|
||||||
|
</div>`
|
||||||
|
: !this._logbookEntries
|
||||||
? html`
|
? html`
|
||||||
<ha-circular-progress
|
<ha-circular-progress
|
||||||
active
|
active
|
||||||
@ -119,17 +127,25 @@ export class MoreInfoLogbook extends LitElement {
|
|||||||
this._lastLogbookDate ||
|
this._lastLogbookDate ||
|
||||||
new Date(new Date().getTime() - 24 * 60 * 60 * 1000);
|
new Date(new Date().getTime() - 24 * 60 * 60 * 1000);
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const [newEntries, traceContexts] = await Promise.all([
|
let newEntries;
|
||||||
getLogbookData(
|
let traceContexts;
|
||||||
this.hass,
|
|
||||||
lastDate.toISOString(),
|
try {
|
||||||
now.toISOString(),
|
[newEntries, traceContexts] = await Promise.all([
|
||||||
this.entityId,
|
getLogbookData(
|
||||||
true
|
this.hass,
|
||||||
),
|
lastDate.toISOString(),
|
||||||
this.hass.user?.is_admin ? loadTraceContexts(this.hass) : {},
|
now.toISOString(),
|
||||||
this._fetchUserPromise,
|
this.entityId,
|
||||||
]);
|
true
|
||||||
|
),
|
||||||
|
this.hass.user?.is_admin ? loadTraceContexts(this.hass) : {},
|
||||||
|
this._fetchUserPromise,
|
||||||
|
]);
|
||||||
|
} catch (err) {
|
||||||
|
this._error = err.message;
|
||||||
|
}
|
||||||
|
|
||||||
this._logbookEntries = this._logbookEntries
|
this._logbookEntries = this._logbookEntries
|
||||||
? [...newEntries, ...this._logbookEntries]
|
? [...newEntries, ...this._logbookEntries]
|
||||||
: newEntries;
|
: newEntries;
|
||||||
|
@ -19,6 +19,7 @@ import {
|
|||||||
} from "../../data/logbook";
|
} from "../../data/logbook";
|
||||||
import { loadTraceContexts, TraceContexts } from "../../data/trace";
|
import { loadTraceContexts, TraceContexts } from "../../data/trace";
|
||||||
import { fetchUsers } from "../../data/user";
|
import { fetchUsers } from "../../data/user";
|
||||||
|
import { showAlertDialog } from "../../dialogs/generic/show-dialog-box";
|
||||||
import "../../layouts/ha-app-layout";
|
import "../../layouts/ha-app-layout";
|
||||||
import { haStyle } from "../../resources/styles";
|
import { haStyle } from "../../resources/styles";
|
||||||
import { HomeAssistant } from "../../types";
|
import { HomeAssistant } from "../../types";
|
||||||
@ -250,18 +251,28 @@ export class HaPanelLogbook extends LitElement {
|
|||||||
|
|
||||||
private async _getData() {
|
private async _getData() {
|
||||||
this._isLoading = true;
|
this._isLoading = true;
|
||||||
const [entries, traceContexts] = await Promise.all([
|
let entries;
|
||||||
getLogbookData(
|
let traceContexts;
|
||||||
this.hass,
|
|
||||||
this._startDate.toISOString(),
|
try {
|
||||||
this._endDate.toISOString(),
|
[entries, traceContexts] = await Promise.all([
|
||||||
this._entityId
|
getLogbookData(
|
||||||
),
|
this.hass,
|
||||||
isComponentLoaded(this.hass, "trace") && this.hass.user?.is_admin
|
this._startDate.toISOString(),
|
||||||
? loadTraceContexts(this.hass)
|
this._endDate.toISOString(),
|
||||||
: {},
|
this._entityId
|
||||||
this._fetchUserPromise,
|
),
|
||||||
]);
|
isComponentLoaded(this.hass, "trace") && this.hass.user?.is_admin
|
||||||
|
? loadTraceContexts(this.hass)
|
||||||
|
: {},
|
||||||
|
this._fetchUserPromise,
|
||||||
|
]);
|
||||||
|
} catch (err) {
|
||||||
|
showAlertDialog(this, {
|
||||||
|
title: this.hass.localize("ui.components.logbook.retrieval_error"),
|
||||||
|
text: err.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this._entries = entries;
|
this._entries = entries;
|
||||||
this._traceContexts = traceContexts;
|
this._traceContexts = traceContexts;
|
||||||
|
@ -66,6 +66,8 @@ export class HuiLogbookCard extends LitElement implements LovelaceCard {
|
|||||||
|
|
||||||
private _fetchUserPromise?: Promise<void>;
|
private _fetchUserPromise?: Promise<void>;
|
||||||
|
|
||||||
|
private _error?: string;
|
||||||
|
|
||||||
private _throttleGetLogbookEntries = throttle(() => {
|
private _throttleGetLogbookEntries = throttle(() => {
|
||||||
this._getLogBookData();
|
this._getLogBookData();
|
||||||
}, 10000);
|
}, 10000);
|
||||||
@ -187,7 +189,15 @@ export class HuiLogbookCard extends LitElement implements LovelaceCard {
|
|||||||
class=${classMap({ "no-header": !this._config!.title })}
|
class=${classMap({ "no-header": !this._config!.title })}
|
||||||
>
|
>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
${!this._logbookEntries
|
${this._error
|
||||||
|
? html`
|
||||||
|
<div class="no-entries">
|
||||||
|
${`${this.hass.localize(
|
||||||
|
"ui.components.logbook.retrieval_error"
|
||||||
|
)}: ${this._error}`}
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
: !this._logbookEntries
|
||||||
? html`
|
? html`
|
||||||
<ha-circular-progress
|
<ha-circular-progress
|
||||||
active
|
active
|
||||||
@ -231,17 +241,22 @@ export class HuiLogbookCard extends LitElement implements LovelaceCard {
|
|||||||
);
|
);
|
||||||
const lastDate = this._lastLogbookDate || hoursToShowDate;
|
const lastDate = this._lastLogbookDate || hoursToShowDate;
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
let newEntries;
|
||||||
|
|
||||||
const [newEntries] = await Promise.all([
|
try {
|
||||||
getLogbookData(
|
newEntries = await Promise.all([
|
||||||
this.hass,
|
getLogbookData(
|
||||||
lastDate.toISOString(),
|
this.hass,
|
||||||
now.toISOString(),
|
lastDate.toISOString(),
|
||||||
this._configEntities!.map((entity) => entity.entity).toString(),
|
now.toISOString(),
|
||||||
true
|
this._configEntities!.map((entity) => entity.entity).toString(),
|
||||||
),
|
true
|
||||||
this._fetchUserPromise,
|
),
|
||||||
]);
|
this._fetchUserPromise,
|
||||||
|
]);
|
||||||
|
} catch (err) {
|
||||||
|
this._error = err.message;
|
||||||
|
}
|
||||||
|
|
||||||
const logbookEntries = this._logbookEntries
|
const logbookEntries = this._logbookEntries
|
||||||
? [...newEntries, ...this._logbookEntries]
|
? [...newEntries, ...this._logbookEntries]
|
||||||
|
@ -304,6 +304,7 @@
|
|||||||
"by": "by",
|
"by": "by",
|
||||||
"by_service": "by service",
|
"by_service": "by service",
|
||||||
"show_trace": "Show trace",
|
"show_trace": "Show trace",
|
||||||
|
"retrieval_error": "Error during logbook entry retrieval",
|
||||||
"messages": {
|
"messages": {
|
||||||
"was_away": "was detected away",
|
"was_away": "was detected away",
|
||||||
"was_at_state": "was detected at {state}",
|
"was_at_state": "was detected at {state}",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user