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
14 changed files with 58 additions and 122 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

@@ -1,5 +1,4 @@
// Tasks to run webpack.
const fs = require("fs");
const gulp = require("gulp");
const webpack = require("webpack");
const WebpackDevServer = require("webpack-dev-server");
@@ -19,11 +18,6 @@ const bothBuilds = (createConfigFunc, params) => [
createConfigFunc({ ...params, latestBuild: false }),
];
const isWsl = fs
.readFileSync("/proc/version", "utf-8")
.toLocaleLowerCase()
.includes("microsoft");
/**
* @param {{
* compiler: import("webpack").Compiler,
@@ -85,7 +79,7 @@ const prodBuild = (conf) =>
gulp.task("webpack-watch-app", () => {
// This command will run forever because we don't close compiler
webpack(createAppConfig({ isProdBuild: false, latestBuild: true })).watch(
{ ignored: /build-translations/, poll: isWsl },
{ ignored: /build-translations/ },
doneHandler()
);
gulp.watch(
@@ -143,7 +137,7 @@ gulp.task("webpack-watch-hassio", () => {
isProdBuild: false,
latestBuild: true,
})
).watch({ ignored: /build-translations/, poll: isWsl }, doneHandler());
).watch({ ignored: /build-translations/ }, doneHandler());
gulp.watch(
path.join(paths.translations_src, "en.json"),

View File

@@ -977,7 +977,6 @@ class HassioAddonInfo extends LitElement {
showDialogSupervisorUpdate(this, {
supervisor: this.supervisor,
name: this.addon.name,
slug: this.addon.slug,
version: this.addon.version_latest,
snapshotParams: {
name: `addon_${this.addon.slug}_${this.addon.version}`,

View File

@@ -161,7 +161,6 @@ export class HassioUpdate extends LitElement {
showDialogSupervisorUpdate(this, {
supervisor: this.supervisor,
name: "Home Assistant Core",
slug: "core",
version: this.supervisor.core.version_latest,
snapshotParams: {
name: `core_${this.supervisor.core.version}`,

View File

@@ -2,32 +2,19 @@ import "@material/mwc-button/mwc-button";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, state } from "lit/decorators";
import { fireEvent } from "../../../../src/common/dom/fire_event";
import "../../../../src/components/ha-checkbox";
import "../../../../src/components/ha-circular-progress";
import "../../../../src/components/ha-dialog";
import "../../../../src/components/ha-settings-row";
import "../../../../src/components/ha-svg-icon";
import "../../../../src/components/ha-switch";
import {
extractApiErrorMessage,
ignoreSupervisorError,
} from "../../../../src/data/hassio/common";
import {
SupervisorFrontendPrefrences,
fetchSupervisorFrontendPreferences,
saveSupervisorFrontendPreferences,
} from "../../../../src/data/supervisor/supervisor";
import { createHassioPartialSnapshot } from "../../../../src/data/hassio/snapshot";
import { haStyle, haStyleDialog } from "../../../../src/resources/styles";
import type { HomeAssistant } from "../../../../src/types";
import { SupervisorDialogSupervisorUpdateParams } from "./show-dialog-update";
import memoizeOne from "memoize-one";
const snapshot_before_update = memoizeOne(
(slug: string, frontendPrefrences: SupervisorFrontendPrefrences) =>
slug in frontendPrefrences.snapshot_before_update
? frontendPrefrences.snapshot_before_update[slug]
: true
);
@customElement("dialog-supervisor-update")
class DialogSupervisorUpdate extends LitElement {
@@ -35,12 +22,12 @@ class DialogSupervisorUpdate extends LitElement {
@state() private _opened = false;
@state() private _createSnapshot = true;
@state() private _action: "snapshot" | "update" | null = null;
@state() private _error?: string;
@state() private _frontendPrefrences?: SupervisorFrontendPrefrences;
@state()
private _dialogParams?: SupervisorDialogSupervisorUpdateParams;
@@ -49,17 +36,14 @@ class DialogSupervisorUpdate extends LitElement {
): Promise<void> {
this._opened = true;
this._dialogParams = params;
this._frontendPrefrences = await fetchSupervisorFrontendPreferences(
this.hass
);
await this.updateComplete;
}
public closeDialog(): void {
this._action = null;
this._createSnapshot = true;
this._error = undefined;
this._dialogParams = undefined;
this._frontendPrefrences = undefined;
fireEvent(this, "dialog-closed", { dialog: this.localName });
}
@@ -72,7 +56,7 @@ class DialogSupervisorUpdate extends LitElement {
}
protected render(): TemplateResult {
if (!this._dialogParams || !this._frontendPrefrences) {
if (!this._dialogParams) {
return html``;
}
return html`
@@ -98,16 +82,6 @@ class DialogSupervisorUpdate extends LitElement {
</div>
<ha-settings-row>
<ha-checkbox
.checked=${snapshot_before_update(
this._dialogParams.slug,
this._frontendPrefrences
)}
haptic
@click=${this._toggleSnapshot}
slot="prefix"
>
</ha-checkbox>
<span slot="heading">
${this._dialogParams.supervisor.localize(
"dialog.update.snapshot"
@@ -120,6 +94,12 @@ class DialogSupervisorUpdate extends LitElement {
this._dialogParams.name
)}
</span>
<ha-switch
.checked=${this._createSnapshot}
haptic
@click=${this._toggleSnapshot}
>
</ha-switch>
</ha-settings-row>
<mwc-button @click=${this.closeDialog} slot="secondaryAction">
${this._dialogParams.supervisor.localize("common.cancel")}
@@ -153,27 +133,12 @@ class DialogSupervisorUpdate extends LitElement {
`;
}
private async _toggleSnapshot(): Promise<void> {
this._frontendPrefrences!.snapshot_before_update[
this._dialogParams!.slug
] = !snapshot_before_update(
this._dialogParams!.slug,
this._frontendPrefrences!
);
await saveSupervisorFrontendPreferences(
this.hass,
this._frontendPrefrences!
);
private _toggleSnapshot() {
this._createSnapshot = !this._createSnapshot;
}
private async _update() {
if (
snapshot_before_update(
this._dialogParams!.slug,
this._frontendPrefrences!
)
) {
if (this._createSnapshot) {
this._action = "snapshot";
try {
await createHassioPartialSnapshot(

View File

@@ -5,7 +5,6 @@ export interface SupervisorDialogSupervisorUpdateParams {
supervisor: Supervisor;
name: string;
version: string;
slug: string;
snapshotParams: any;
updateHandler: () => Promise<void>;
}

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,

View File

@@ -164,7 +164,6 @@ class HassioCoreInfo extends LitElement {
showDialogSupervisorUpdate(this, {
supervisor: this.supervisor,
name: "Home Assistant Core",
slug: "core",
version: this.supervisor.core.version_latest,
snapshotParams: {
name: `core_${this.supervisor.core.version}`,

View File

@@ -2,7 +2,6 @@ import { Connection, getCollection } from "home-assistant-js-websocket";
import { Store } from "home-assistant-js-websocket/dist/store";
import { LocalizeFunc } from "../../common/translations/localize";
import { HomeAssistant } from "../../types";
import { fetchFrontendUserData, saveFrontendUserData } from "../frontend";
import { HassioAddonsInfo } from "../hassio/addon";
import { HassioHassOSInfo, HassioHostInfo } from "../hassio/host";
import { NetworkInfo } from "../hassio/network";
@@ -14,28 +13,6 @@ import {
} from "../hassio/supervisor";
import { SupervisorStore } from "./store";
export interface SupervisorFrontendPrefrences {
snapshot_before_update: Record<string, boolean>;
}
declare global {
interface FrontendUserData {
supervisor: SupervisorFrontendPrefrences;
}
}
export const fetchSupervisorFrontendPreferences = async (
hass: HomeAssistant
): Promise<SupervisorFrontendPrefrences> => {
const stored = await fetchFrontendUserData(hass.connection, "supervisor");
return stored || { snapshot_before_update: {} };
};
export const saveSupervisorFrontendPreferences = (
hass: HomeAssistant,
data: SupervisorFrontendPrefrences
) => saveFrontendUserData(hass.connection, "supervisor", data);
export const supervisorWSbaseCommand = {
type: "supervisor/api",
method: "GET",

View File

@@ -108,28 +108,12 @@ export const showOptionsFlowDialog = (
`;
},
renderShowFormProgressHeader(hass, step) {
return (
hass.localize(
`component.${configEntry.domain}.options.step.${step.step_id}.title`
) || hass.localize(`component.${configEntry.domain}.title`)
);
renderShowFormProgressHeader(_hass, _step) {
return "";
},
renderShowFormProgressDescription(hass, step) {
const description = hass.localize(
`component.${configEntry.domain}.options.progress.${step.progress_action}`,
step.description_placeholders
);
return description
? html`
<ha-markdown
allowsvg
breaks
.content=${description}
></ha-markdown>
`
: "";
renderShowFormProgressDescription(_hass, _step) {
return "";
},
}
);

View File

@@ -3822,7 +3822,7 @@
"faq_link": "[%key:ui::panel::my::faq_link%]",
"error": "[%key:ui::panel::my::error%]",
"error_addon_not_found": "Add-on not found",
"error_addon_not_started": "The requested add-on is not running. Please start it first",
"error_addon_not_started": "The requested add-on are not running. Please start it first",
"error_addon_not_installed": "The requested add-on is not installed. Please install it first",
"error_addon_no_ingress": "The requested add-on does not support ingress"
},

View File

@@ -1138,7 +1138,6 @@
},
"zha_reconfigure_device": {
"attribute": "Атрибут",
"battery_device_warning": "Ще трябва да събудите устройствата, захранвани с батерии, преди да започнете процеса на преконфигуриране. Вижте ръководствата на вашите устройства за инструкции как да ги събудите.",
"bind_header": "Обвързване",
"button_hide": "Скрийте детайлите",
"button_show": "Покажи детайли",
@@ -1148,7 +1147,6 @@
"configuring_alt": "Конфигуриране",
"heading": "Преконфигуриране на устройство",
"in_progress": "Устройството се преконфигурира. Това може да отнеме известно време.",
"introduction": "Преконфигуриране на устройство във вашата Zigbee мрежа. Използвайте тази функция, ако устройството ви не функционира правилно.",
"min_max_change": "мин/макс/промяна",
"reporting_header": "Отчитане",
"run_in_background": "Можете да затворите този диалогов прозорец и преконфигурирането ще продължи във фонов режим.",
@@ -2660,7 +2658,6 @@
"header": "Z-Wave конфигурация на устройството",
"introduction": "Управление и настройване на специфични конфигурационни параметри на подбраното устройството (възел, node)",
"parameter_is_read_only": "Този параметър е само за четене.",
"set_param_accepted": "Параметърът е актуализиран.",
"set_param_error": "Възникна грешка.",
"zwave_js_device_database": "Z-Wave JS база данни с устройства"
},