Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle starting the frontend before finished loading integrations #6068

Merged
merged 12 commits into from
May 29, 2020
6 changes: 5 additions & 1 deletion src/data/connection-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

import { fireEvent, HASSDomEvent } from "../common/dom/fire_event";

export type ConnectionStatus = "connected" | "auth-invalid" | "disconnected";
export type ConnectionStatus =
| "connected"
| "started"
| "auth-invalid"
| "disconnected";

declare global {
// for fire event
Expand Down
1 change: 1 addition & 0 deletions src/fake_data/demo_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const demoConfig: HassConfig = {
whitelist_external_dirs: [],
config_source: "storage",
safe_mode: false,
state: "RUNNING",
internal_url: "http://homeassistant.local:8123",
external_url: null,
};
23 changes: 23 additions & 0 deletions src/layouts/partial-panel-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class PartialPanelResolver extends HassRouterPage {

@property() public narrow?: boolean;

private _waitForStart = false;

protected updated(changedProps: PropertyValues) {
super.updated(changedProps);

Expand Down Expand Up @@ -128,6 +130,27 @@ class PartialPanelResolver extends HassRouterPage {
private async _updateRoutes(oldPanels?: HomeAssistant["panels"]) {
this.routerOptions = getRoutes(this.hass.panels);

if (
!this._waitForStart &&
this._currentPage &&
!this.hass.panels[this._currentPage]
) {
if (this.hass.config.state !== "RUNNING") {
bramkragten marked this conversation as resolved.
Show resolved Hide resolved
this._waitForStart = true;
window.addEventListener("connection-status", (ev) => {
bramkragten marked this conversation as resolved.
Show resolved Hide resolved
if (ev.detail === "started") {
this._waitForStart = false;
this.rebuild();
}
});
if (this.lastChild) {
this.removeChild(this.lastChild);
}
this.appendChild(this.createLoadingScreen());
return;
}
}

if (
!oldPanels ||
!deepEqual(
Expand Down
6 changes: 5 additions & 1 deletion src/mixins/subscribe-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ export const SubscribeMixin = <T extends Constructor<UpdatingElement>>(
if (this.__unsubs) {
while (this.__unsubs.length) {
const unsub = this.__unsubs.pop()!;
Promise.resolve(unsub).then((unsubFunc) => unsubFunc());
if (unsub instanceof Promise) {
unsub.then((unsubFunc) => unsubFunc());
} else {
unsub();
}
}
this.__unsubs = undefined;
}
Expand Down
1 change: 0 additions & 1 deletion src/panels/lovelace/badges/hui-state-label-badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { HomeAssistant } from "../../../types";
import { actionHandler } from "../common/directives/action-handler-directive";
import { handleAction } from "../common/handle-action";
import { hasAction } from "../common/has-action";
import "../components/hui-warning-element";
import { LovelaceBadge } from "../types";
import { StateLabelBadgeConfig } from "./types";

Expand Down
12 changes: 4 additions & 8 deletions src/panels/lovelace/cards/hui-alarm-panel-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from "../../../data/alarm_control_panel";
import type { HomeAssistant } from "../../../types";
import { findEntities } from "../common/find-entites";
import "../components/hui-warning";
import { createEntityNotFoundWarning } from "../components/hui-warning";
import type { LovelaceCard } from "../types";
import { AlarmPanelCardConfig } from "./types";

Expand Down Expand Up @@ -151,13 +151,9 @@ class HuiAlarmPanelCard extends LitElement implements LovelaceCard {

if (!stateObj) {
return html`
<hui-warning
>${this.hass.localize(
"ui.panel.lovelace.warning.entity_not_found",
"entity",
this._config.entity
)}</hui-warning
>
<hui-warning>
${createEntityNotFoundWarning(this.hass, this._config.entity)}
</hui-warning>
`;
}

Expand Down
12 changes: 4 additions & 8 deletions src/panels/lovelace/cards/hui-button-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { actionHandler } from "../common/directives/action-handler-directive";
import { findEntities } from "../common/find-entites";
import { handleAction } from "../common/handle-action";
import { hasAction } from "../common/has-action";
import "../components/hui-warning";
import { createEntityNotFoundWarning } from "../components/hui-warning";
import { LovelaceCard, LovelaceCardEditor } from "../types";
import { ButtonCardConfig } from "./types";

Expand Down Expand Up @@ -145,13 +145,9 @@ export class HuiButtonCard extends LitElement implements LovelaceCard {

if (this._config.entity && !stateObj) {
return html`
<hui-warning
>${this.hass.localize(
"ui.panel.lovelace.warning.entity_not_found",
"entity",
this._config.entity
)}</hui-warning
>
<hui-warning>
${createEntityNotFoundWarning(this.hass, this._config.entity)}
</hui-warning>
Comment on lines +148 to +150
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why actually expect caller to still wrap it in hui-warning and not just return a template from createEntityNotFoundWarning ?

`;
}

Expand Down
12 changes: 4 additions & 8 deletions src/panels/lovelace/cards/hui-entity-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { UNAVAILABLE_STATES } from "../../../data/entity";
import { HomeAssistant } from "../../../types";
import { findEntities } from "../common/find-entites";
import { hasConfigOrEntityChanged } from "../common/has-changed";
import "../components/hui-warning";
import { createEntityNotFoundWarning } from "../components/hui-warning";
import { createHeaderFooterElement } from "../create-element/create-header-footer-element";
import {
LovelaceCard,
Expand Down Expand Up @@ -92,13 +92,9 @@ export class HuiEntityCard extends LitElement implements LovelaceCard {

if (!stateObj) {
return html`
<hui-warning
>${this.hass.localize(
"ui.panel.lovelace.warning.entity_not_found",
"entity",
this._config.entity
)}</hui-warning
>
<hui-warning>
${createEntityNotFoundWarning(this.hass, this._config.entity)}
</hui-warning>
`;
}

Expand Down
12 changes: 4 additions & 8 deletions src/panels/lovelace/cards/hui-gauge-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import "../../../components/ha-card";
import type { HomeAssistant } from "../../../types";
import { findEntities } from "../common/find-entites";
import { hasConfigOrEntityChanged } from "../common/has-changed";
import "../components/hui-warning";
import { createEntityNotFoundWarning } from "../components/hui-warning";
import type { LovelaceCard, LovelaceCardEditor } from "../types";
import type { GaugeCardConfig } from "./types";
import { debounce } from "../../../common/util/debounce";
Expand Down Expand Up @@ -105,13 +105,9 @@ class HuiGaugeCard extends LitElement implements LovelaceCard {

if (!stateObj) {
return html`
<hui-warning
>${this.hass.localize(
"ui.panel.lovelace.warning.entity_not_found",
"entity",
this._config.entity
)}</hui-warning
>
<hui-warning>
${createEntityNotFoundWarning(this.hass, this._config.entity)}
</hui-warning>
`;
}

Expand Down
7 changes: 2 additions & 5 deletions src/panels/lovelace/cards/hui-glance-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import "../components/hui-warning-element";
import { LovelaceCard, LovelaceCardEditor } from "../types";
import "../components/hui-timestamp-display";
import { GlanceCardConfig, GlanceConfigEntity } from "./types";
import { createEntityNotFoundWarning } from "../components/hui-warning";

@customElement("hui-glance-card")
export class HuiGlanceCard extends LitElement implements LovelaceCard {
Expand Down Expand Up @@ -212,11 +213,7 @@ export class HuiGlanceCard extends LitElement implements LovelaceCard {
if (!stateObj) {
return html`
<hui-warning-element
label=${this.hass!.localize(
"ui.panel.lovelace.warning.entity_not_found",
"entity",
entityConf.entity
)}
.label=${createEntityNotFoundWarning(this.hass!, entityConf.entity)}
></hui-warning-element>
`;
}
Expand Down
12 changes: 4 additions & 8 deletions src/panels/lovelace/cards/hui-light-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { findEntities } from "../common/find-entites";
import { handleAction } from "../common/handle-action";
import { hasAction } from "../common/has-action";
import { hasConfigOrEntityChanged } from "../common/has-changed";
import "../components/hui-warning";
import { createEntityNotFoundWarning } from "../components/hui-warning";
import { LovelaceCard, LovelaceCardEditor } from "../types";
import { LightCardConfig } from "./types";

Expand Down Expand Up @@ -89,13 +89,9 @@ export class HuiLightCard extends LitElement implements LovelaceCard {

if (!stateObj) {
return html`
<hui-warning
>${this.hass.localize(
"ui.panel.lovelace.warning.entity_not_found",
"entity",
this._config.entity
)}</hui-warning
>
<hui-warning>
${createEntityNotFoundWarning(this.hass, this._config.entity)}
</hui-warning>
`;
}

Expand Down
12 changes: 4 additions & 8 deletions src/panels/lovelace/cards/hui-media-control-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import { findEntities } from "../common/find-entites";
import { hasConfigOrEntityChanged } from "../common/has-changed";
import "../components/hui-marquee";
import type { LovelaceCard, LovelaceCardEditor } from "../types";
import "../components/hui-warning";
import { createEntityNotFoundWarning } from "../components/hui-warning";
import { MediaControlCardConfig } from "./types";
import { installResizeObserver } from "../common/install-resize-observer";

Expand Down Expand Up @@ -266,13 +266,9 @@ export class HuiMediaControlCard extends LitElement implements LovelaceCard {

if (!stateObj) {
return html`
<hui-warning
>${this.hass.localize(
"ui.panel.lovelace.warning.entity_not_found",
"entity",
this._config.entity
)}</hui-warning
>
<hui-warning>
${createEntityNotFoundWarning(this.hass, this._config.entity)}
</hui-warning>
`;
}

Expand Down
12 changes: 4 additions & 8 deletions src/panels/lovelace/cards/hui-picture-entity-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { handleAction } from "../common/handle-action";
import { hasAction } from "../common/has-action";
import { hasConfigOrEntityChanged } from "../common/has-changed";
import "../components/hui-image";
import "../components/hui-warning";
import { createEntityNotFoundWarning } from "../components/hui-warning";
import { LovelaceCard, LovelaceCardEditor } from "../types";
import { PictureEntityCardConfig } from "./types";

Expand Down Expand Up @@ -116,13 +116,9 @@ class HuiPictureEntityCard extends LitElement implements LovelaceCard {

if (!stateObj) {
return html`
<hui-warning
>${this.hass.localize(
"ui.panel.lovelace.warning.entity_not_found",
"entity",
this._config.entity
)}</hui-warning
>
<hui-warning>
${createEntityNotFoundWarning(this.hass, this._config.entity)}
</hui-warning>
`;
}

Expand Down
7 changes: 2 additions & 5 deletions src/panels/lovelace/cards/hui-picture-glance-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import "../components/hui-image";
import "../components/hui-warning-element";
import { LovelaceCard, LovelaceCardEditor } from "../types";
import { PictureGlanceCardConfig, PictureGlanceEntityConfig } from "./types";
import { createEntityNotFoundWarning } from "../components/hui-warning";

const STATES_OFF = new Set(["closed", "locked", "not_home", "off"]);

Expand Down Expand Up @@ -229,11 +230,7 @@ class HuiPictureGlanceCard extends LitElement implements LovelaceCard {
if (!stateObj) {
return html`
<hui-warning-element
label=${this.hass!.localize(
"ui.panel.lovelace.warning.entity_not_found",
"entity",
entityConf.entity
)}
.label=${createEntityNotFoundWarning(this.hass!, entityConf.entity)}
></hui-warning-element>
`;
}
Expand Down
11 changes: 4 additions & 7 deletions src/panels/lovelace/cards/hui-plant-status-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { findEntities } from "../common/find-entites";
import { hasConfigOrEntityChanged } from "../common/has-changed";
import { LovelaceCard, LovelaceCardEditor } from "../types";
import { PlantAttributeTarget, PlantStatusCardConfig } from "./types";
import { createEntityNotFoundWarning } from "../components/hui-warning";

const SENSORS = {
moisture: "hass:water",
Expand Down Expand Up @@ -105,13 +106,9 @@ class HuiPlantStatusCard extends LitElement implements LovelaceCard {

if (!stateObj) {
return html`
<hui-warning
>${this.hass.localize(
"ui.panel.lovelace.warning.entity_not_found",
"entity",
this._config.entity
)}</hui-warning
>
<hui-warning>
${createEntityNotFoundWarning(this.hass, this._config.entity)}
</hui-warning>
`;
}

Expand Down
67 changes: 67 additions & 0 deletions src/panels/lovelace/cards/hui-starting-card.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import "@material/mwc-button/mwc-button";
import {
css,
CSSResult,
customElement,
html,
LitElement,
property,
TemplateResult,
} from "lit-element";
import "../../../components/ha-card";
import { HomeAssistant } from "../../../types";
import { LovelaceCard } from "../types";
import { LovelaceCardConfig } from "../../../data/lovelace";
import "@polymer/paper-spinner/paper-spinner-lite";

@customElement("hui-starting-card")
export class HuiStartingCard extends LitElement implements LovelaceCard {
@property() public hass?: HomeAssistant;

public getCardSize(): number {
return 2;
}

public setConfig(_config: LovelaceCardConfig): void {
// eslint-disable-next-line
}

protected render(): TemplateResult {
if (!this.hass) {
return html``;
}

return html`
<ha-card
.header="${this.hass.localize(
"ui.panel.lovelace.cards.starting.header"
)}"
>
<div class="card-content">
${this.hass.localize("ui.panel.lovelace.cards.starting.description")}
</div>
<paper-spinner-lite active></paper-spinner-lite>
</ha-card>
`;
}

static get styles(): CSSResult {
return css`
.content {
margin-top: -1em;
padding: 16px;
}
paper-spinner-lite {
display: block;
margin: auto;
padding: 20px;
}
`;
}
}

declare global {
interface HTMLElementTagNameMap {
"hui-starting-card": HuiStartingCard;
}
}