Compare commits

...

3 Commits

Author SHA1 Message Date
Joakim Sørensen
f5c42d24ed Lmit _initializeLocalize 2021-06-15 09:20:21 +00:00
Joakim Sørensen
04a4d26b18 Don't strip supervisor 2021-06-15 09:00:48 +00:00
Joakim Sørensen
ed6b54e5c6 Don't initialize supervisor object for ingress 2021-06-14 10:06:26 +00:00
4 changed files with 37 additions and 14 deletions

View File

@@ -266,7 +266,6 @@ gulp.task(taskName, function () {
TRANSLATION_FRAGMENTS.forEach((fragment) => {
delete data.ui.panel[fragment];
});
delete data.supervisor;
return data;
})
)

View File

@@ -61,10 +61,11 @@ class HassioRouter extends HassRouterPage {
el.hass = this.hass;
el.narrow = this.narrow;
el.route = route;
el.supervisor = this.supervisor;
if (el.localName === "hassio-ingress-view") {
el.ingressPanel = this.panel.config && this.panel.config.ingress;
} else {
el.supervisor = this.supervisor;
}
}

View File

@@ -21,7 +21,6 @@ import {
createHassioSession,
validateHassioSession,
} from "../../../src/data/hassio/ingress";
import { Supervisor } from "../../../src/data/supervisor/supervisor";
import { showAlertDialog } from "../../../src/dialogs/generic/show-dialog-box";
import "../../../src/layouts/hass-loading-screen";
import "../../../src/layouts/hass-subpage";
@@ -31,11 +30,9 @@ import { HomeAssistant, Route } from "../../../src/types";
class HassioIngressView extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property({ attribute: false }) public supervisor!: Supervisor;
@property({ attribute: false }) public route!: Route;
@property() public route!: Route;
@property() public ingressPanel = false;
@property({ type: Boolean }) public ingressPanel = false;
@state() private _addon?: HassioAddonDetails;
@@ -102,14 +99,14 @@ class HassioIngressView extends LitElement {
}
if (!addonInfo.version) {
await showAlertDialog(this, {
text: this.supervisor.localize("my.error_addon_not_installed"),
text: this.hass.localize("supervisor.my.error_addon_not_installed"),
title: addonInfo.name,
});
await nextRender();
navigate(`/hassio/addon/${addonInfo.slug}/info`, { replace: true });
} else if (!addonInfo.ingress) {
await showAlertDialog(this, {
text: this.supervisor.localize("my.error_addon_no_ingress"),
text: this.hass.localize("supervisor.my.error_addon_no_ingress"),
title: addonInfo.name,
});
await nextRender();

View File

@@ -1,6 +1,7 @@
import { Collection, UnsubscribeFunc } from "home-assistant-js-websocket";
import { LitElement, PropertyValues } from "lit";
import { property, state } from "lit/decorators";
import memoizeOne from "memoize-one";
import { atLeastVersion } from "../../src/common/config/version";
import { computeLocalize } from "../../src/common/translations/localize";
import { fetchHassioAddonsInfo } from "../../src/data/hassio/addon";
@@ -15,6 +16,7 @@ import {
fetchHassioHomeAssistantInfo,
fetchHassioInfo,
fetchHassioSupervisorInfo,
HassioPanelInfo,
} from "../../src/data/hassio/supervisor";
import { fetchSupervisorStore } from "../../src/data/supervisor/store";
import {
@@ -25,7 +27,7 @@ import {
} from "../../src/data/supervisor/supervisor";
import { ProvideHassLitMixin } from "../../src/mixins/provide-hass-lit-mixin";
import { urlSyncMixin } from "../../src/state/url-sync-mixin";
import { HomeAssistant } from "../../src/types";
import { HomeAssistant, Route } from "../../src/types";
import { getTranslation } from "../../src/util/common-translation";
declare global {
@@ -35,6 +37,11 @@ declare global {
}
}
const isIngress = memoizeOne(
(panel?: HassioPanelInfo, route?: Route) =>
(panel?.config && "ingress" in panel.config) || route?.path === "/ingress"
);
export class SupervisorBaseElement extends urlSyncMixin(
ProvideHassLitMixin(LitElement)
) {
@@ -42,19 +49,23 @@ export class SupervisorBaseElement extends urlSyncMixin(
localize: () => "",
};
@property({ attribute: false }) public panel?: HassioPanelInfo;
@property({ attribute: false }) public route?: Route;
@state() private _unsubs: Record<string, UnsubscribeFunc> = {};
@state() private _collections: Record<string, Collection<unknown>> = {};
@state() private _language = "en";
public connectedCallback(): void {
super.connectedCallback();
this._initializeLocalize();
}
@state() private _ingress = true;
public disconnectedCallback() {
super.disconnectedCallback();
if (this._ingress) {
return;
}
Object.keys(this._unsubs).forEach((unsub) => {
this._unsubs[unsub]();
});
@@ -62,6 +73,11 @@ export class SupervisorBaseElement extends urlSyncMixin(
protected updated(changedProperties: PropertyValues) {
super.updated(changedProperties);
this._ingress = isIngress(this.panel, this.route);
if (this._ingress) {
return;
}
if (changedProperties.has("hass")) {
const oldHass = changedProperties.get("hass") as
| HomeAssistant
@@ -103,17 +119,27 @@ export class SupervisorBaseElement extends urlSyncMixin(
protected firstUpdated(changedProps: PropertyValues): void {
super.firstUpdated(changedProps);
this._ingress = isIngress(this.panel, this.route);
if (this._ingress) {
return;
}
if (
this._language !== this.hass.language &&
this.hass.language !== undefined
) {
this._language = this.hass.language;
}
this._initializeLocalize();
this._initSupervisor();
}
private async _initializeLocalize() {
if (this._ingress) {
return;
}
const { language, data } = await getTranslation(
null,
this._language,