Show error screen when connection fails (#11030)

This commit is contained in:
Paulus Schoutsen 2021-12-27 02:43:38 -08:00 committed by GitHub
parent 322d965539
commit 3e062ba673
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 34 deletions

View File

@ -34,8 +34,6 @@ const panelUrl = (path: string) => {
export class HomeAssistantAppEl extends QuickBarMixin(HassElement) { export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
@state() private _route: Route; @state() private _route: Route;
@state() private _error = false;
private _panelUrl: string; private _panelUrl: string;
private _haVersion?: string; private _haVersion?: string;
@ -44,8 +42,6 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
private _visiblePromiseResolve?: () => void; private _visiblePromiseResolve?: () => void;
private _visibleLaunchScreen = true;
constructor() { constructor() {
super(); super();
const path = curPath(); const path = curPath();
@ -62,27 +58,22 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
this._panelUrl = panelUrl(path); this._panelUrl = panelUrl(path);
} }
protected render() { protected renderHass() {
if (this._isHassComplete() && this.hass) { return html`
return html` <home-assistant-main
<home-assistant-main .hass=${this.hass}
.hass=${this.hass} .route=${this._route}
.route=${this._route} ></home-assistant-main>
></home-assistant-main> `;
`;
}
return "";
} }
update(changedProps) { update(changedProps) {
super.update(changedProps); if (this.hass?.states && this.hass.config && this.hass.services) {
this.render = this.renderHass;
// Remove launch screen if main gui is loaded this.update = super.update;
if (this._isHassComplete() && this._visibleLaunchScreen) {
this._visibleLaunchScreen = false;
removeLaunchScreen(); removeLaunchScreen();
} }
super.update(changedProps);
} }
protected firstUpdated(changedProps) { protected firstUpdated(changedProps) {
@ -129,10 +120,9 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
}); });
// Render launch screen info box (loading data / error message) // Render launch screen info box (loading data / error message)
if (!this._isHassComplete() && this._visibleLaunchScreen) { // if Home Assistant is not loaded yet.
renderLaunchScreenInfoBox( if (this.render !== this.renderHass) {
html`<ha-init-page .error=${this._error}></ha-init-page>` this._renderInitInfo(false);
);
} }
} }
@ -188,7 +178,7 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
if (window.hassConnection) { if (window.hassConnection) {
result = await window.hassConnection; result = await window.hassConnection;
} else { } else {
// In the edge case that // In the edge case that core.ts loads before app.ts
result = await new Promise((resolve) => { result = await new Promise((resolve) => {
window.hassConnectionReady = resolve; window.hassConnectionReady = resolve;
}); });
@ -198,7 +188,7 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
this._haVersion = conn.haVersion; this._haVersion = conn.haVersion;
this.initializeHass(auth, conn); this.initializeHass(auth, conn);
} catch (err: any) { } catch (err: any) {
this._error = true; this._renderInitInfo(true);
} }
} }
@ -255,12 +245,10 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
} }
} }
private _isHassComplete(): boolean { private _renderInitInfo(error: boolean) {
if (this.hass?.states && this.hass.config && this.hass.services) { renderLaunchScreenInfoBox(
return true; html`<ha-init-page .error=${error}></ha-init-page>`
} );
return false;
} }
} }

View File

@ -7,9 +7,9 @@ export const removeLaunchScreen = () => {
} }
}; };
export const renderLaunchScreenInfoBox = (element: TemplateResult) => { export const renderLaunchScreenInfoBox = (content: TemplateResult) => {
const infoBoxElement = document.getElementById("ha-launch-screen-info-box"); const infoBoxElement = document.getElementById("ha-launch-screen-info-box");
if (infoBoxElement) { if (infoBoxElement) {
render(element, infoBoxElement); render(content, infoBoxElement);
} }
}; };