Fix supervisor not loading Firefox (#17146)

This commit is contained in:
Bram Kragten 2023-07-03 15:25:59 +02:00 committed by GitHub
parent 6a2cad1af3
commit a3b87a6e7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 6 deletions

View File

@ -23,6 +23,7 @@ import {
SupervisorObject, SupervisorObject,
supervisorCollection, supervisorCollection,
SupervisorKeys, SupervisorKeys,
cleanupSupervisorCollection,
} from "../../src/data/supervisor/supervisor"; } from "../../src/data/supervisor/supervisor";
import { ProvideHassLitMixin } from "../../src/mixins/provide-hass-lit-mixin"; import { ProvideHassLitMixin } from "../../src/mixins/provide-hass-lit-mixin";
import { urlSyncMixin } from "../../src/state/url-sync-mixin"; import { urlSyncMixin } from "../../src/state/url-sync-mixin";
@ -67,6 +68,10 @@ export class SupervisorBaseElement extends urlSyncMixin(
this._unsubs[unsub](); this._unsubs[unsub]();
delete this._unsubs[unsub]; delete this._unsubs[unsub];
}); });
Object.keys(this._collections).forEach((collection) => {
cleanupSupervisorCollection(this.hass.connection, collection);
});
this._collections = {};
this.removeEventListener( this.removeEventListener(
"supervisor-collection-refresh", "supervisor-collection-refresh",
this._handleSupervisorStoreRefreshEvent this._handleSupervisorStoreRefreshEvent
@ -114,7 +119,9 @@ export class SupervisorBaseElement extends urlSyncMixin(
private async _handleSupervisorStoreRefreshEvent(ev) { private async _handleSupervisorStoreRefreshEvent(ev) {
const collection = ev.detail.collection; const collection = ev.detail.collection;
if (atLeastVersion(this.hass.config.version, 2021, 2, 4)) { if (atLeastVersion(this.hass.config.version, 2021, 2, 4)) {
this._collections[collection].refresh(); if (collection in this._collections) {
this._collections[collection].refresh();
}
return; return;
} }
@ -129,11 +136,17 @@ export class SupervisorBaseElement extends urlSyncMixin(
if (this._unsubs[collection]) { if (this._unsubs[collection]) {
this._unsubs[collection](); this._unsubs[collection]();
} }
this._unsubs[collection] = this._collections[collection].subscribe((data) => try {
this._updateSupervisor({ this._unsubs[collection] = this._collections[collection].subscribe(
[collection]: data, (data) =>
}) this._updateSupervisor({
); [collection]: data,
})
);
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
}
} }
private async _initSupervisor(): Promise<void> { private async _initSupervisor(): Promise<void> {

View File

@ -132,3 +132,6 @@ export const getSupervisorEventCollection = (
subscribeSupervisorEventUpdates(connection, store, key), subscribeSupervisorEventUpdates(connection, store, key),
{ unsubGrace: false } { unsubGrace: false }
); );
export const cleanupSupervisorCollection = (conn: Connection, key: string) =>
delete conn[`_supervisor${key}Event`];