mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-18 23:06:40 +00:00
Remove usage of discovery info (#10015)
This commit is contained in:
parent
360c2cbfa3
commit
e55df73a91
@ -8,10 +8,6 @@ import {
|
|||||||
AuthUrlSearchParams,
|
AuthUrlSearchParams,
|
||||||
fetchAuthProviders,
|
fetchAuthProviders,
|
||||||
} from "../data/auth";
|
} from "../data/auth";
|
||||||
import {
|
|
||||||
DiscoveryInformation,
|
|
||||||
fetchDiscoveryInformation,
|
|
||||||
} from "../data/discovery";
|
|
||||||
import { litLocalizeLiteMixin } from "../mixins/lit-localize-lite-mixin";
|
import { litLocalizeLiteMixin } from "../mixins/lit-localize-lite-mixin";
|
||||||
import { registerServiceWorker } from "../util/register-service-worker";
|
import { registerServiceWorker } from "../util/register-service-worker";
|
||||||
import "./ha-auth-flow";
|
import "./ha-auth-flow";
|
||||||
@ -29,8 +25,6 @@ class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
|
|||||||
|
|
||||||
@state() private _authProviders?: AuthProvider[];
|
@state() private _authProviders?: AuthProvider[];
|
||||||
|
|
||||||
@state() private _discovery?: DiscoveryInformation;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.translationFragment = "page-authorize";
|
this.translationFragment = "page-authorize";
|
||||||
@ -58,17 +52,14 @@ class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
|
|||||||
// the name with a bold tag.
|
// the name with a bold tag.
|
||||||
const loggingInWith = document.createElement("div");
|
const loggingInWith = document.createElement("div");
|
||||||
loggingInWith.innerText = this.localize(
|
loggingInWith.innerText = this.localize(
|
||||||
this._discovery?.location_name
|
"ui.panel.page-authorize.logging_in_with",
|
||||||
? "ui.panel.page-authorize.logging_in_to_with"
|
|
||||||
: "ui.panel.page-authorize.logging_in_with",
|
|
||||||
"locationName",
|
|
||||||
"LOCATION",
|
|
||||||
"authProviderName",
|
"authProviderName",
|
||||||
"NAME"
|
"NAME"
|
||||||
);
|
);
|
||||||
loggingInWith.innerHTML = loggingInWith.innerHTML
|
loggingInWith.innerHTML = loggingInWith.innerHTML.replace(
|
||||||
.replace("**LOCATION**", `<b>${this._discovery?.location_name}</b>`)
|
"**NAME**",
|
||||||
.replace("**NAME**", `<b>${this._authProvider!.name}</b>`);
|
`<b>${this._authProvider!.name}</b>`
|
||||||
|
);
|
||||||
|
|
||||||
const inactiveProviders = this._authProviders.filter(
|
const inactiveProviders = this._authProviders.filter(
|
||||||
(prv) => prv !== this._authProvider
|
(prv) => prv !== this._authProvider
|
||||||
@ -108,7 +99,6 @@ class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
|
|||||||
protected firstUpdated(changedProps: PropertyValues) {
|
protected firstUpdated(changedProps: PropertyValues) {
|
||||||
super.firstUpdated(changedProps);
|
super.firstUpdated(changedProps);
|
||||||
this._fetchAuthProviders();
|
this._fetchAuthProviders();
|
||||||
this._fetchDiscoveryInfo();
|
|
||||||
|
|
||||||
if (matchMedia("(prefers-color-scheme: dark)").matches) {
|
if (matchMedia("(prefers-color-scheme: dark)").matches) {
|
||||||
applyThemesOnElement(
|
applyThemesOnElement(
|
||||||
@ -144,10 +134,6 @@ class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _fetchDiscoveryInfo() {
|
|
||||||
this._discovery = await fetchDiscoveryInformation();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async _fetchAuthProviders() {
|
private async _fetchAuthProviders() {
|
||||||
// Fetch auth providers
|
// Fetch auth providers
|
||||||
try {
|
try {
|
||||||
|
@ -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();
|
|
||||||
};
|
|
@ -1,6 +1,15 @@
|
|||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
import { handleFetchPromise } from "../util/hass-call-api";
|
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
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||||
export interface OnboardingCoreConfigStepResponse {}
|
export interface OnboardingCoreConfigStepResponse {}
|
||||||
|
|
||||||
@ -65,3 +74,15 @@ export const onboardIntegrationStep = (
|
|||||||
"onboarding/integration",
|
"onboarding/integration",
|
||||||
params
|
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();
|
||||||
|
};
|
||||||
|
@ -13,14 +13,12 @@ import { extractSearchParamsObject } from "../common/url/search-params";
|
|||||||
import { subscribeOne } from "../common/util/subscribe-one";
|
import { subscribeOne } from "../common/util/subscribe-one";
|
||||||
import { AuthUrlSearchParams, hassUrl } from "../data/auth";
|
import { AuthUrlSearchParams, hassUrl } from "../data/auth";
|
||||||
import {
|
import {
|
||||||
DiscoveryInformation,
|
InstallationType,
|
||||||
fetchDiscoveryInformation,
|
|
||||||
} from "../data/discovery";
|
|
||||||
import {
|
|
||||||
fetchOnboardingOverview,
|
fetchOnboardingOverview,
|
||||||
OnboardingResponses,
|
OnboardingResponses,
|
||||||
OnboardingStep,
|
OnboardingStep,
|
||||||
onboardIntegrationStep,
|
onboardIntegrationStep,
|
||||||
|
fetchInstallationType,
|
||||||
} from "../data/onboarding";
|
} from "../data/onboarding";
|
||||||
import { subscribeUser } from "../data/ws-user";
|
import { subscribeUser } from "../data/ws-user";
|
||||||
import { litLocalizeLiteMixin } from "../mixins/lit-localize-lite-mixin";
|
import { litLocalizeLiteMixin } from "../mixins/lit-localize-lite-mixin";
|
||||||
@ -71,7 +69,7 @@ class HaOnboarding extends litLocalizeLiteMixin(HassElement) {
|
|||||||
|
|
||||||
@state() private _steps?: OnboardingStep[];
|
@state() private _steps?: OnboardingStep[];
|
||||||
|
|
||||||
@state() private _discoveryInformation?: DiscoveryInformation;
|
@state() private _installation_type?: InstallationType;
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
const step = this._curStep()!;
|
const step = this._curStep()!;
|
||||||
@ -92,7 +90,7 @@ class HaOnboarding extends litLocalizeLiteMixin(HassElement) {
|
|||||||
? html`<onboarding-restore-backup
|
? html`<onboarding-restore-backup
|
||||||
.localize=${this.localize}
|
.localize=${this.localize}
|
||||||
.restoring=${this._restoring}
|
.restoring=${this._restoring}
|
||||||
.discoveryInformation=${this._discoveryInformation}
|
.installtionType=${this._installation_type}
|
||||||
@restoring=${this._restoringBackup}
|
@restoring=${this._restoringBackup}
|
||||||
>
|
>
|
||||||
</onboarding-restore-backup>`
|
</onboarding-restore-backup>`
|
||||||
@ -130,7 +128,7 @@ class HaOnboarding extends litLocalizeLiteMixin(HassElement) {
|
|||||||
protected firstUpdated(changedProps: PropertyValues) {
|
protected firstUpdated(changedProps: PropertyValues) {
|
||||||
super.firstUpdated(changedProps);
|
super.firstUpdated(changedProps);
|
||||||
this._fetchOnboardingSteps();
|
this._fetchOnboardingSteps();
|
||||||
this._fetchDiscoveryInformation();
|
this._fetchInstallationType();
|
||||||
import("./onboarding-integrations");
|
import("./onboarding-integrations");
|
||||||
import("./onboarding-core-config");
|
import("./onboarding-core-config");
|
||||||
registerServiceWorker(this, false);
|
registerServiceWorker(this, false);
|
||||||
@ -174,9 +172,9 @@ class HaOnboarding extends litLocalizeLiteMixin(HassElement) {
|
|||||||
this._restoring = true;
|
this._restoring = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _fetchDiscoveryInformation(): Promise<void> {
|
private async _fetchInstallationType(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const response = await fetchDiscoveryInformation();
|
const response = await fetchInstallationType();
|
||||||
this._supervisor = [
|
this._supervisor = [
|
||||||
"Home Assistant OS",
|
"Home Assistant OS",
|
||||||
"Home Assistant Supervised",
|
"Home Assistant Supervised",
|
||||||
|
@ -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 { showBackupUploadDialog } from "../../hassio/src/dialogs/backup/show-dialog-backup-upload";
|
||||||
import type { LocalizeFunc } from "../common/translations/localize";
|
import type { LocalizeFunc } from "../common/translations/localize";
|
||||||
import "../components/ha-card";
|
import "../components/ha-card";
|
||||||
import {
|
|
||||||
DiscoveryInformation,
|
|
||||||
fetchDiscoveryInformation,
|
|
||||||
} from "../data/discovery";
|
|
||||||
import { makeDialogManager } from "../dialogs/make-dialog-manager";
|
import { makeDialogManager } from "../dialogs/make-dialog-manager";
|
||||||
import { ProvideHassLitMixin } from "../mixins/provide-hass-lit-mixin";
|
import { ProvideHassLitMixin } from "../mixins/provide-hass-lit-mixin";
|
||||||
import { haStyle } from "../resources/styles";
|
import { haStyle } from "../resources/styles";
|
||||||
import "./onboarding-loading";
|
import "./onboarding-loading";
|
||||||
|
import { fetchInstallationType, InstallationType } from "../data/onboarding";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface HASSDomEvents {
|
interface HASSDomEvents {
|
||||||
@ -30,7 +27,7 @@ class OnboardingRestoreBackup extends ProvideHassLitMixin(LitElement) {
|
|||||||
@property({ type: Boolean }) public restoring = false;
|
@property({ type: Boolean }) public restoring = false;
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
public discoveryInformation?: DiscoveryInformation;
|
public installationType?: InstallationType;
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
return this.restoring
|
return this.restoring
|
||||||
@ -64,17 +61,11 @@ class OnboardingRestoreBackup extends ProvideHassLitMixin(LitElement) {
|
|||||||
private async _checkRestoreStatus(): Promise<void> {
|
private async _checkRestoreStatus(): Promise<void> {
|
||||||
if (this.restoring) {
|
if (this.restoring) {
|
||||||
try {
|
try {
|
||||||
const response = await fetchDiscoveryInformation();
|
await fetchInstallationType();
|
||||||
|
} catch (err) {
|
||||||
if (
|
if ((err as Error).message === "unauthorized") {
|
||||||
!this.discoveryInformation ||
|
|
||||||
this.discoveryInformation.uuid !== response.uuid
|
|
||||||
) {
|
|
||||||
// When the UUID changes, the restore is complete
|
|
||||||
window.location.replace("/");
|
window.location.replace("/");
|
||||||
}
|
}
|
||||||
} catch (err) {
|
|
||||||
// We fully expected issues with fetching info untill restore is complete.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3517,7 +3517,6 @@
|
|||||||
"page-authorize": {
|
"page-authorize": {
|
||||||
"initializing": "Initializing",
|
"initializing": "Initializing",
|
||||||
"authorizing_client": "You're about to give {clientId} access to your Home Assistant instance.",
|
"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}**.",
|
"logging_in_with": "Logging in with **{authProviderName}**.",
|
||||||
"pick_auth_provider": "Or log in with",
|
"pick_auth_provider": "Or log in with",
|
||||||
"abort_intro": "Login aborted",
|
"abort_intro": "Login aborted",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user