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

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");
if (infoBoxElement) {
render(element, infoBoxElement);
render(content, infoBoxElement);
}
};