From 82eb33a7d488beb421e24abf4f0d637adf8b2028 Mon Sep 17 00:00:00 2001 From: Ian Richardson Date: Sun, 28 Oct 2018 15:09:41 -0500 Subject: [PATCH] Convert hui-climate-entity-row to TypeScript/LitElement (#1899) * Convert hui-climate-entity-row to TypeScript/LitElement * Address review comments * Address review comments --- .../lovelace/common/create-row-element.js | 2 +- .../entity-rows/hui-climate-entity-row.js | 61 ----------------- .../entity-rows/hui-climate-entity-row.ts | 65 +++++++++++++++++++ 3 files changed, 66 insertions(+), 62 deletions(-) delete mode 100644 src/panels/lovelace/entity-rows/hui-climate-entity-row.js create mode 100644 src/panels/lovelace/entity-rows/hui-climate-entity-row.ts diff --git a/src/panels/lovelace/common/create-row-element.js b/src/panels/lovelace/common/create-row-element.js index 28931e06de..e2b02e9712 100644 --- a/src/panels/lovelace/common/create-row-element.js +++ b/src/panels/lovelace/common/create-row-element.js @@ -1,6 +1,6 @@ import { fireEvent } from "../../../common/dom/fire_event.js"; -import "../entity-rows/hui-climate-entity-row.js"; +import "../entity-rows/hui-climate-entity-row"; import "../entity-rows/hui-cover-entity-row.js"; import "../entity-rows/hui-group-entity-row.js"; import "../entity-rows/hui-input-number-entity-row.js"; diff --git a/src/panels/lovelace/entity-rows/hui-climate-entity-row.js b/src/panels/lovelace/entity-rows/hui-climate-entity-row.js deleted file mode 100644 index 78ac84d2b6..0000000000 --- a/src/panels/lovelace/entity-rows/hui-climate-entity-row.js +++ /dev/null @@ -1,61 +0,0 @@ -import { html } from "@polymer/polymer/lib/utils/html-tag.js"; -import { PolymerElement } from "@polymer/polymer/polymer-element.js"; - -import "../../../components/ha-climate-state.js"; -import "../components/hui-generic-entity-row.js"; - -class HuiClimateEntityRow extends PolymerElement { - static get template() { - return html` - ${this.styleTemplate} - - ${this.climateControlTemplate} - - `; - } - - static get styleTemplate() { - return html` - - `; - } - - static get climateControlTemplate() { - return html` - - `; - } - - static get properties() { - return { - hass: Object, - _config: Object, - _stateObj: { - type: Object, - computed: "_computeStateObj(hass.states, _config.entity)", - }, - }; - } - - _computeStateObj(states, entityId) { - return states && entityId in states ? states[entityId] : null; - } - - setConfig(config) { - if (!config || !config.entity) { - throw new Error("Entity not configured."); - } - this._config = config; - } -} -customElements.define("hui-climate-entity-row", HuiClimateEntityRow); diff --git a/src/panels/lovelace/entity-rows/hui-climate-entity-row.ts b/src/panels/lovelace/entity-rows/hui-climate-entity-row.ts new file mode 100644 index 0000000000..074ef40c33 --- /dev/null +++ b/src/panels/lovelace/entity-rows/hui-climate-entity-row.ts @@ -0,0 +1,65 @@ +import { html, LitElement } from "@polymer/lit-element"; +import { TemplateResult } from "lit-html"; + +import "../../../components/ha-climate-state.js"; +import "../components/hui-generic-entity-row.js"; + +import { HomeAssistant } from "../../../types.js"; +import { EntityRow, EntityConfig } from "./types.js"; + +class HuiClimateEntityRow extends LitElement implements EntityRow { + public hass?: HomeAssistant; + private _config?: EntityConfig; + + static get properties() { + return { + hass: {}, + _config: {}, + }; + } + + public setConfig(config: EntityConfig): void { + if (!config || !config.entity) { + throw new Error("Invalid Configuration: 'entity' required"); + } + + this._config = config; + } + + protected render(): TemplateResult { + if (!this.hass || !this._config) { + return html``; + } + + return html` + ${this.renderStyle()} + + + + `; + } + + private renderStyle(): TemplateResult { + return html` + + `; + } +} + +declare global { + interface HTMLElementTagNameMap { + "hui-climate-entity-row": HuiClimateEntityRow; + } +} + +customElements.define("hui-climate-entity-row", HuiClimateEntityRow);