Add humidifier entity row (#6213)

Co-authored-by: Zack Barett <zackbarett@hey.com>
This commit is contained in:
Shulyaka 2020-09-24 17:45:33 +03:00 committed by GitHub
parent 4ba6698c4b
commit 245c825cbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 81 additions and 1 deletions

View File

@ -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",

View File

@ -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`
<hui-warning>
${createEntityNotFoundWarning(this.hass, this._config.entity)}
</hui-warning>
`;
}
return html`
<hui-generic-entity-row
.hass=${this.hass}
.config=${this._config}
.secondaryText=${stateObj.attributes.humidity
? `${this.hass!.localize("ui.card.humidifier.humidity")}:
${stateObj.attributes.humidity}%${
stateObj.attributes.mode
? ` (${
this.hass!.localize(
`state_attributes.humidifier.mode.${stateObj.attributes.mode}`
) || stateObj.attributes.mode
})`
: ""
}`
: ""}
>
<ha-entity-toggle
.hass=${this.hass}
.stateObj=${stateObj}
></ha-entity-toggle>
</hui-generic-entity-row>
`;
}
}
declare global {
interface HTMLElementTagNameMap {
"hui-humidifier-entity-row": HuiHumidifierEntityRow;
}
}