- Entity not available: [[_config.entity]]
-
- `;
- }
-
- static get styleTemplate() {
- return html`
-
- `;
- }
-
- static get properties() {
- return {
- hass: Object,
- _config: Object,
- _stateObj: {
- type: Object,
- computed: "_computeStateObj(hass.states, _config.entity)",
- },
- _selected: {
- type: String,
- observer: "_selectedChanged",
- },
- };
- }
-
- setConfig(config) {
- if (!config || !config.entity) {
- throw new Error("Entity not configured.");
- }
- this._config = config;
- }
-
- _computeStateObj(states, entityId) {
- return states && entityId in states ? states[entityId] : null;
- }
-
- _computeName(name, stateObj) {
- return name || computeStateName(stateObj);
- }
-
- _computeSelected(stateObj) {
- return stateObj.attributes.options.indexOf(stateObj.state);
- }
-
- _selectedChanged(option) {
- // Selected Option will transition to '' before transitioning to new value
- if (option === "" || option === this._stateObj.state) {
- return;
- }
- this.hass.callService("input_select", "select_option", {
- option: option,
- entity_id: this._stateObj.entity_id,
- });
- }
-
- _stopPropagation(ev) {
- ev.stopPropagation();
- }
-}
-customElements.define("hui-input-select-entity-row", HuiInputSelectEntityRow);
diff --git a/src/panels/lovelace/entity-rows/hui-input-select-entity-row.ts b/src/panels/lovelace/entity-rows/hui-input-select-entity-row.ts
new file mode 100644
index 0000000000..eca12feb00
--- /dev/null
+++ b/src/panels/lovelace/entity-rows/hui-input-select-entity-row.ts
@@ -0,0 +1,112 @@
+import { html, LitElement, PropertyDeclarations } from "@polymer/lit-element";
+import { repeat } from "lit-html/directives/repeat";
+import { TemplateResult } from "lit-html";
+import "@polymer/paper-dropdown-menu/paper-dropdown-menu";
+import "@polymer/paper-item/paper-item";
+import "@polymer/paper-listbox/paper-listbox";
+
+import "../../../components/entity/state-badge";
+import "./hui-error-entity-row";
+
+import computeStateName from "../../../common/entity/compute_state_name";
+import { HomeAssistant } from "../../../types";
+import { EntityRow, EntityConfig } from "./types";
+import { setOption } from "../../../data/input-select";
+
+class HuiInputSelectEntityRow extends LitElement implements EntityRow {
+ public hass?: HomeAssistant;
+ private _config?: EntityConfig;
+
+ static get properties(): PropertyDeclarations {
+ 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``;
+ }
+
+ const stateObj = this.hass.states[this._config.entity];
+
+ if (!stateObj) {
+ return html`
+