From 245c825cbf32c451a474bad1dffc081d4db20781 Mon Sep 17 00:00:00 2001 From: Shulyaka Date: Thu, 24 Sep 2020 17:45:33 +0300 Subject: [PATCH] Add humidifier entity row (#6213) Co-authored-by: Zack Barett --- .../create-element/create-row-element.ts | 3 +- .../entity-rows/hui-humidifier-entity-row.ts | 79 +++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 src/panels/lovelace/entity-rows/hui-humidifier-entity-row.ts diff --git a/src/panels/lovelace/create-element/create-row-element.ts b/src/panels/lovelace/create-element/create-row-element.ts index 178192fa48..433b50e0a5 100644 --- a/src/panels/lovelace/create-element/create-row-element.ts +++ b/src/panels/lovelace/create-element/create-row-element.ts @@ -24,6 +24,7 @@ const LAZY_LOAD_TYPES = { "climate-entity": () => import("../entity-rows/hui-climate-entity-row"), "cover-entity": () => import("../entity-rows/hui-cover-entity-row"), "group-entity": () => import("../entity-rows/hui-group-entity-row"), + "humidifier-entity": () => import("../entity-rows/hui-humidifier-entity-row"), "input-datetime-entity": () => import("../entity-rows/hui-input-datetime-entity-row"), "input-number-entity": () => @@ -51,7 +52,7 @@ const DOMAIN_TO_ELEMENT_TYPE = { cover: "cover", fan: "toggle", group: "group", - humidifier: "toggle", + humidifier: "humidifier", input_boolean: "toggle", input_number: "input-number", input_select: "input-select", diff --git a/src/panels/lovelace/entity-rows/hui-humidifier-entity-row.ts b/src/panels/lovelace/entity-rows/hui-humidifier-entity-row.ts new file mode 100644 index 0000000000..58a8dc79ae --- /dev/null +++ b/src/panels/lovelace/entity-rows/hui-humidifier-entity-row.ts @@ -0,0 +1,79 @@ +import { + customElement, + html, + LitElement, + property, + PropertyValues, + TemplateResult, +} from "lit-element"; +import "../../../components/entity/ha-entity-toggle"; +import { HomeAssistant } from "../../../types"; +import { hasConfigOrEntityChanged } from "../common/has-changed"; +import "../components/hui-generic-entity-row"; +import { createEntityNotFoundWarning } from "../components/hui-warning"; +import { EntityConfig, LovelaceRow } from "./types"; + +@customElement("hui-humidifier-entity-row") +class HuiHumidifierEntityRow extends LitElement implements LovelaceRow { + @property() public hass?: HomeAssistant; + + @property() private _config?: EntityConfig; + + public setConfig(config: EntityConfig): void { + if (!config || !config.entity) { + throw new Error("Invalid Configuration: 'entity' required"); + } + + this._config = config; + } + + protected shouldUpdate(changedProps: PropertyValues): boolean { + return hasConfigOrEntityChanged(this, changedProps); + } + + protected render(): TemplateResult { + if (!this.hass || !this._config) { + return html``; + } + + const stateObj = this.hass.states[this._config.entity]; + + if (!stateObj) { + return html` + + ${createEntityNotFoundWarning(this.hass, this._config.entity)} + + `; + } + + return html` + + + + `; + } +} + +declare global { + interface HTMLElementTagNameMap { + "hui-humidifier-entity-row": HuiHumidifierEntityRow; + } +}