Remove usage of discovery info (#10015)

This commit is contained in:
Joakim Sørensen 2021-09-11 20:38:35 +02:00 committed by GitHub
parent 360c2cbfa3
commit e55df73a91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 59 deletions

View File

@ -8,10 +8,6 @@ import {
AuthUrlSearchParams,
fetchAuthProviders,
} from "../data/auth";
import {
DiscoveryInformation,
fetchDiscoveryInformation,
} from "../data/discovery";
import { litLocalizeLiteMixin } from "../mixins/lit-localize-lite-mixin";
import { registerServiceWorker } from "../util/register-service-worker";
import "./ha-auth-flow";
@ -29,8 +25,6 @@ class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
@state() private _authProviders?: AuthProvider[];
@state() private _discovery?: DiscoveryInformation;
constructor() {
super();
this.translationFragment = "page-authorize";
@ -58,17 +52,14 @@ class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
// the name with a bold tag.
const loggingInWith = document.createElement("div");
loggingInWith.innerText = this.localize(
this._discovery?.location_name
? "ui.panel.page-authorize.logging_in_to_with"
: "ui.panel.page-authorize.logging_in_with",
"locationName",
"LOCATION",
"ui.panel.page-authorize.logging_in_with",
"authProviderName",
"NAME"
);
loggingInWith.innerHTML = loggingInWith.innerHTML
.replace("**LOCATION**", `<b>${this._discovery?.location_name}</b>`)
.replace("**NAME**", `<b>${this._authProvider!.name}</b>`);
loggingInWith.innerHTML = loggingInWith.innerHTML.replace(
"**NAME**",
`<b>${this._authProvider!.name}</b>`
);
const inactiveProviders = this._authProviders.filter(
(prv) => prv !== this._authProvider
@ -108,7 +99,6 @@ class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
protected firstUpdated(changedProps: PropertyValues) {
super.firstUpdated(changedProps);
this._fetchAuthProviders();
this._fetchDiscoveryInfo();
if (matchMedia("(prefers-color-scheme: dark)").matches) {
applyThemesOnElement(
@ -144,10 +134,6 @@ class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
}
}
private async _fetchDiscoveryInfo() {
this._discovery = await fetchDiscoveryInformation();
}
private async _fetchAuthProviders() {
// Fetch auth providers
try {

View File

@ -1,16 +0,0 @@
export interface DiscoveryInformation {
uuid: string;
base_url: string | null;
external_url: string | null;
internal_url: string | null;
location_name: string;
installation_type: string;
requires_api_password: boolean;
version: string;
}
export const fetchDiscoveryInformation =
async (): Promise<DiscoveryInformation> => {
const response = await fetch("/api/discovery_info", { method: "GET" });
return response.json();
};

View File

@ -1,6 +1,15 @@
import { HomeAssistant } from "../types";
import { handleFetchPromise } from "../util/hass-call-api";
export interface InstallationType {
installation_type:
| "Home Assistant Operating System"
| "Home Assistant Container"
| "Home Assistant Supervised"
| "Home Assistant Core"
| "Unknown";
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface OnboardingCoreConfigStepResponse {}
@ -65,3 +74,15 @@ export const onboardIntegrationStep = (
"onboarding/integration",
params
);
export const fetchInstallationType = async (): Promise<InstallationType> => {
const response = await fetch("/api/onboarding/installation_type", {
method: "GET",
});
if (response.status === 401) {
throw Error("unauthorized");
}
return response.json();
};

View File

@ -13,14 +13,12 @@ import { extractSearchParamsObject } from "../common/url/search-params";
import { subscribeOne } from "../common/util/subscribe-one";
import { AuthUrlSearchParams, hassUrl } from "../data/auth";
import {
DiscoveryInformation,
fetchDiscoveryInformation,
} from "../data/discovery";
import {
InstallationType,
fetchOnboardingOverview,
OnboardingResponses,
OnboardingStep,
onboardIntegrationStep,
fetchInstallationType,
} from "../data/onboarding";
import { subscribeUser } from "../data/ws-user";
import { litLocalizeLiteMixin } from "../mixins/lit-localize-lite-mixin";
@ -71,7 +69,7 @@ class HaOnboarding extends litLocalizeLiteMixin(HassElement) {
@state() private _steps?: OnboardingStep[];
@state() private _discoveryInformation?: DiscoveryInformation;
@state() private _installation_type?: InstallationType;
protected render(): TemplateResult {
const step = this._curStep()!;
@ -92,7 +90,7 @@ class HaOnboarding extends litLocalizeLiteMixin(HassElement) {
? html`<onboarding-restore-backup
.localize=${this.localize}
.restoring=${this._restoring}
.discoveryInformation=${this._discoveryInformation}
.installtionType=${this._installation_type}
@restoring=${this._restoringBackup}
>
</onboarding-restore-backup>`
@ -130,7 +128,7 @@ class HaOnboarding extends litLocalizeLiteMixin(HassElement) {
protected firstUpdated(changedProps: PropertyValues) {
super.firstUpdated(changedProps);
this._fetchOnboardingSteps();
this._fetchDiscoveryInformation();
this._fetchInstallationType();
import("./onboarding-integrations");
import("./onboarding-core-config");
registerServiceWorker(this, false);
@ -174,9 +172,9 @@ class HaOnboarding extends litLocalizeLiteMixin(HassElement) {
this._restoring = true;
}
private async _fetchDiscoveryInformation(): Promise<void> {
private async _fetchInstallationType(): Promise<void> {
try {
const response = await fetchDiscoveryInformation();
const response = await fetchInstallationType();
this._supervisor = [
"Home Assistant OS",
"Home Assistant Supervised",

View File

@ -6,14 +6,11 @@ import { showHassioBackupDialog } from "../../hassio/src/dialogs/backup/show-dia
import { showBackupUploadDialog } from "../../hassio/src/dialogs/backup/show-dialog-backup-upload";
import type { LocalizeFunc } from "../common/translations/localize";
import "../components/ha-card";
import {
DiscoveryInformation,
fetchDiscoveryInformation,
} from "../data/discovery";
import { makeDialogManager } from "../dialogs/make-dialog-manager";
import { ProvideHassLitMixin } from "../mixins/provide-hass-lit-mixin";
import { haStyle } from "../resources/styles";
import "./onboarding-loading";
import { fetchInstallationType, InstallationType } from "../data/onboarding";
declare global {
interface HASSDomEvents {
@ -30,7 +27,7 @@ class OnboardingRestoreBackup extends ProvideHassLitMixin(LitElement) {
@property({ type: Boolean }) public restoring = false;
@property({ attribute: false })
public discoveryInformation?: DiscoveryInformation;
public installationType?: InstallationType;
protected render(): TemplateResult {
return this.restoring
@ -64,17 +61,11 @@ class OnboardingRestoreBackup extends ProvideHassLitMixin(LitElement) {
private async _checkRestoreStatus(): Promise<void> {
if (this.restoring) {
try {
const response = await fetchDiscoveryInformation();
if (
!this.discoveryInformation ||
this.discoveryInformation.uuid !== response.uuid
) {
// When the UUID changes, the restore is complete
await fetchInstallationType();
} catch (err) {
if ((err as Error).message === "unauthorized") {
window.location.replace("/");
}
} catch (err) {
// We fully expected issues with fetching info untill restore is complete.
}
}
}

View File

@ -3517,7 +3517,6 @@
"page-authorize": {
"initializing": "Initializing",
"authorizing_client": "You're about to give {clientId} access to your Home Assistant instance.",
"logging_in_to_with": "Logging in to **{locationName}** with **{authProviderName}**.",
"logging_in_with": "Logging in with **{authProviderName}**.",
"pick_auth_provider": "Or log in with",
"abort_intro": "Login aborted",