From f08bbdd6d0bcf9bb2ab16014a37357d914c3f5c8 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 29 Oct 2018 22:20:00 +0100 Subject: [PATCH] Propagate hass correctly --- .../lovelace/cards/hui-entities-card.ts | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/src/panels/lovelace/cards/hui-entities-card.ts b/src/panels/lovelace/cards/hui-entities-card.ts index 55eddca2bcdf..ff064930f407 100644 --- a/src/panels/lovelace/cards/hui-entities-card.ts +++ b/src/panels/lovelace/cards/hui-entities-card.ts @@ -1,4 +1,10 @@ -import { html, LitElement, PropertyDeclarations } from "@polymer/lit-element"; +import { + html, + LitElement, + PropertyDeclarations, + PropertyValues, +} from "@polymer/lit-element"; +import { TemplateResult } from "lit-html"; import "../../../components/ha-card.js"; import "../components/hui-entities-toggle.js"; @@ -36,13 +42,19 @@ class HuiEntitiesCard extends hassLocalizeLitMixin(LitElement) protected _config?: Config; protected _configEntities?: ConfigEntity[]; - set hass(hass) { + set hass(hass: HomeAssistant) { this._hass = hass; - this.shadowRoot!.querySelectorAll("#states > *").forEach( + this.shadowRoot!.querySelectorAll("#states > div > *").forEach( (element: unknown) => { (element as EntityRow).hass = hass; } ); + const entitiesToggle = this.shadowRoot!.querySelector( + "hui-entities-toggle" + ); + if (entitiesToggle) { + (entitiesToggle as any).hass = hass; + } } static get properties(): PropertyDeclarations { @@ -51,7 +63,7 @@ class HuiEntitiesCard extends hassLocalizeLitMixin(LitElement) }; } - public getCardSize() { + public getCardSize(): number { if (!this._config) { return 0; } @@ -59,7 +71,7 @@ class HuiEntitiesCard extends hassLocalizeLitMixin(LitElement) return (this._config.title ? 1 : 0) + this._config.entities.length; } - public setConfig(config: Config) { + public setConfig(config: Config): void { const entities = processConfigEntities(config.entities); for (const entity of entities) { if ( @@ -78,14 +90,18 @@ class HuiEntitiesCard extends hassLocalizeLitMixin(LitElement) this._configEntities = entities; } - protected render() { + protected updated(_changedProperties: PropertyValues): void { + if (this._hass && this._config) { + applyThemesOnElement(this, this._hass.themes, this._config.theme); + } + } + + protected render(): TemplateResult { if (!this._config || !this._hass) { return html``; } const { show_header_toggle, title } = this._config; - applyThemesOnElement(this, this._hass.themes, this._config.theme); - return html` ${this.renderStyle()} @@ -104,8 +120,7 @@ class HuiEntitiesCard extends hassLocalizeLitMixin(LitElement) .entities="${this._configEntities!.map( (conf) => conf.entity )}" - > - ` + >` } ` } @@ -118,7 +133,7 @@ class HuiEntitiesCard extends hassLocalizeLitMixin(LitElement) `; } - private renderStyle() { + private renderStyle(): TemplateResult { return html`