mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 03:06:41 +00:00
Logbook card loading fix (#23853)
* the call to unsubscribe will never do anything * await the subscription when subscribing to logbook * removed unneeded if wrapped call to subscribeLogbook in try/catch remove return values from _subscribeLogbookPeriod
This commit is contained in:
parent
a329553ce1
commit
dc8d483e8b
@ -76,7 +76,7 @@ export class HaLogbook extends LitElement {
|
|||||||
|
|
||||||
@state() private _error?: string;
|
@state() private _error?: string;
|
||||||
|
|
||||||
private _subscribed?: Promise<(() => Promise<void>) | undefined>;
|
private _subscribed?: (() => Promise<void>) | undefined;
|
||||||
|
|
||||||
private _liveUpdatesEnabled = true;
|
private _liveUpdatesEnabled = true;
|
||||||
|
|
||||||
@ -211,12 +211,9 @@ export class HaLogbook extends LitElement {
|
|||||||
private async _unsubscribe(): Promise<void> {
|
private async _unsubscribe(): Promise<void> {
|
||||||
if (this._subscribed) {
|
if (this._subscribed) {
|
||||||
try {
|
try {
|
||||||
const unsub = await this._subscribed;
|
await this._subscribed();
|
||||||
if (unsub) {
|
this._subscribed = undefined;
|
||||||
await unsub();
|
this._pendingStreamMessages = [];
|
||||||
this._subscribed = undefined;
|
|
||||||
this._pendingStreamMessages = [];
|
|
||||||
}
|
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
console.error("Error unsubscribing:", err);
|
console.error("Error unsubscribing:", err);
|
||||||
@ -284,34 +281,34 @@ export class HaLogbook extends LitElement {
|
|||||||
throw new Error("Unexpected time specified");
|
throw new Error("Unexpected time specified");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _subscribeLogbookPeriod(logbookPeriod: LogbookTimePeriod) {
|
private async _subscribeLogbookPeriod(
|
||||||
|
logbookPeriod: LogbookTimePeriod
|
||||||
|
): Promise<void> {
|
||||||
if (this._subscribed) {
|
if (this._subscribed) {
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
// Ensure any previous subscription is cleaned up
|
try {
|
||||||
await this._unsubscribe();
|
this._subscribed = await subscribeLogbook(
|
||||||
this._subscribed = subscribeLogbook(
|
this.hass,
|
||||||
this.hass,
|
(streamMessage) => {
|
||||||
(streamMessage) => {
|
// "recent" means start time is a sliding window
|
||||||
// "recent" means start time is a sliding window
|
// so we need to calculate an expireTime to
|
||||||
// so we need to calculate an expireTime to
|
// purge old events
|
||||||
// purge old events
|
if (!this._subscribed) {
|
||||||
if (!this._subscribed) {
|
// Message came in before we had a chance to unload
|
||||||
// Message came in before we had a chance to unload
|
return;
|
||||||
return;
|
}
|
||||||
}
|
this._processOrQueueStreamMessage(streamMessage);
|
||||||
this._processOrQueueStreamMessage(streamMessage);
|
},
|
||||||
},
|
logbookPeriod.startTime.toISOString(),
|
||||||
logbookPeriod.startTime.toISOString(),
|
logbookPeriod.endTime.toISOString(),
|
||||||
logbookPeriod.endTime.toISOString(),
|
this.entityIds,
|
||||||
this.entityIds,
|
this.deviceIds
|
||||||
this.deviceIds
|
);
|
||||||
).catch((err) => {
|
} catch (err: any) {
|
||||||
this._subscribed = undefined;
|
this._subscribed = undefined;
|
||||||
this._error = err;
|
this._error = err;
|
||||||
return undefined;
|
}
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _getLogBookData() {
|
private async _getLogBookData() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user