mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 03:06:41 +00:00
Fix logbook stream subscription (#25927)
This commit is contained in:
parent
b81cd37776
commit
dd4cb1df72
@ -114,9 +114,13 @@ const getLogbookDataFromServer = (
|
|||||||
|
|
||||||
export const subscribeLogbook = (
|
export const subscribeLogbook = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
callbackFunction: (message: LogbookStreamMessage) => void,
|
callbackFunction: (
|
||||||
|
message: LogbookStreamMessage,
|
||||||
|
subscriptionId: number
|
||||||
|
) => void,
|
||||||
startDate: string,
|
startDate: string,
|
||||||
endDate: string,
|
endDate: string,
|
||||||
|
subscriptionId: number,
|
||||||
entityIds?: string[],
|
entityIds?: string[],
|
||||||
deviceIds?: string[]
|
deviceIds?: string[]
|
||||||
): Promise<UnsubscribeFunc> => {
|
): Promise<UnsubscribeFunc> => {
|
||||||
@ -140,7 +144,7 @@ export const subscribeLogbook = (
|
|||||||
params.device_ids = deviceIds;
|
params.device_ids = deviceIds;
|
||||||
}
|
}
|
||||||
return hass.connection.subscribeMessage<LogbookStreamMessage>(
|
return hass.connection.subscribeMessage<LogbookStreamMessage>(
|
||||||
(message) => callbackFunction(message),
|
(message) => callbackFunction(message, subscriptionId),
|
||||||
params
|
params
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -88,6 +88,8 @@ export class HaLogbook extends LitElement {
|
|||||||
1000
|
1000
|
||||||
);
|
);
|
||||||
|
|
||||||
|
private _logbookSubscriptionId = 0;
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
if (!isComponentLoaded(this.hass, "logbook")) {
|
if (!isComponentLoaded(this.hass, "logbook")) {
|
||||||
return nothing;
|
return nothing;
|
||||||
@ -278,13 +280,20 @@ export class HaLogbook extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
this._logbookSubscriptionId++;
|
||||||
|
|
||||||
this._unsubLogbook = subscribeLogbook(
|
this._unsubLogbook = subscribeLogbook(
|
||||||
this.hass,
|
this.hass,
|
||||||
(streamMessage) => {
|
(streamMessage, subscriptionId) => {
|
||||||
|
if (subscriptionId !== this._logbookSubscriptionId) {
|
||||||
|
// Ignore messages from previous subscriptions
|
||||||
|
return;
|
||||||
|
}
|
||||||
this._processOrQueueStreamMessage(streamMessage);
|
this._processOrQueueStreamMessage(streamMessage);
|
||||||
},
|
},
|
||||||
logbookPeriod.startTime.toISOString(),
|
logbookPeriod.startTime.toISOString(),
|
||||||
logbookPeriod.endTime.toISOString(),
|
logbookPeriod.endTime.toISOString(),
|
||||||
|
this._logbookSubscriptionId,
|
||||||
this.entityIds,
|
this.entityIds,
|
||||||
this.deviceIds
|
this.deviceIds
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user