mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +00:00
Clean system health subscription after data is collected (#17665)
This commit is contained in:
parent
aa2b2b0d16
commit
bbb6fccaec
@ -69,7 +69,7 @@ type SystemHealthEvent =
|
||||
|
||||
export const subscribeSystemHealthInfo = (
|
||||
hass: HomeAssistant,
|
||||
callback: (info: SystemHealthInfo) => void
|
||||
callback: (info: SystemHealthInfo | undefined) => void
|
||||
) => {
|
||||
let data = {};
|
||||
|
||||
@ -82,6 +82,7 @@ export const subscribeSystemHealthInfo = (
|
||||
}
|
||||
if (updateEvent.type === "finish") {
|
||||
unsubProm.then((unsub) => unsub());
|
||||
callback(undefined);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,9 @@ class DialogSystemInformation extends LitElement {
|
||||
|
||||
@state() private _opened = false;
|
||||
|
||||
private _subscriptions?: Array<UnsubscribeFunc | Promise<UnsubscribeFunc>>;
|
||||
private _systemHealthSubscription?: Promise<UnsubscribeFunc>;
|
||||
|
||||
private _hassIOSubscription?: UnsubscribeFunc;
|
||||
|
||||
public showDialog(): void {
|
||||
this._opened = true;
|
||||
@ -86,48 +88,43 @@ class DialogSystemInformation extends LitElement {
|
||||
}
|
||||
|
||||
private _subscribe(): void {
|
||||
const subs: Array<UnsubscribeFunc | Promise<UnsubscribeFunc>> = [];
|
||||
if (isComponentLoaded(this.hass, "system_health")) {
|
||||
subs.push(
|
||||
subscribeSystemHealthInfo(this.hass!, (info) => {
|
||||
this._systemInfo = info;
|
||||
})
|
||||
this._systemHealthSubscription = subscribeSystemHealthInfo(
|
||||
this.hass,
|
||||
(info) => {
|
||||
if (!info) {
|
||||
this._systemHealthSubscription = undefined;
|
||||
} else {
|
||||
this._systemInfo = info;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (isComponentLoaded(this.hass, "hassio")) {
|
||||
subs.push(
|
||||
subscribePollingCollection(
|
||||
this.hass,
|
||||
async () => {
|
||||
this._supervisorStats = await fetchHassioStats(
|
||||
this.hass,
|
||||
"supervisor"
|
||||
);
|
||||
this._coreStats = await fetchHassioStats(this.hass, "core");
|
||||
},
|
||||
10000
|
||||
)
|
||||
this._hassIOSubscription = subscribePollingCollection(
|
||||
this.hass,
|
||||
async () => {
|
||||
this._supervisorStats = await fetchHassioStats(
|
||||
this.hass,
|
||||
"supervisor"
|
||||
);
|
||||
this._coreStats = await fetchHassioStats(this.hass, "core");
|
||||
},
|
||||
10000
|
||||
);
|
||||
|
||||
fetchHassioResolution(this.hass).then((data) => {
|
||||
this._resolutionInfo = data;
|
||||
});
|
||||
}
|
||||
|
||||
this._subscriptions = subs;
|
||||
}
|
||||
|
||||
private _unsubscribe() {
|
||||
while (this._subscriptions?.length) {
|
||||
const unsub = this._subscriptions.pop()!;
|
||||
if (unsub instanceof Promise) {
|
||||
unsub.then((unsubFunc) => unsubFunc());
|
||||
} else {
|
||||
unsub();
|
||||
}
|
||||
}
|
||||
this._subscriptions = undefined;
|
||||
this._systemHealthSubscription?.then((unsubFunc) => unsubFunc());
|
||||
this._systemHealthSubscription = undefined;
|
||||
this._hassIOSubscription?.();
|
||||
this._hassIOSubscription = undefined;
|
||||
|
||||
this._systemInfo = undefined;
|
||||
this._resolutionInfo = undefined;
|
||||
|
Loading…
x
Reference in New Issue
Block a user