mirror of
				https://github.com/home-assistant/frontend.git
				synced 2025-11-04 00:19:47 +00:00 
			
		
		
		
	Compare commits
	
		
			3 Commits
		
	
	
		
			20210127.7
			...
			attributes
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					39200b62d5 | ||
| 
						 | 
					0eb28ea733 | ||
| 
						 | 
					62d471888f | 
@@ -1,3 +1,4 @@
 | 
				
			|||||||
 | 
					import "@material/mwc-icon-button/mwc-icon-button";
 | 
				
			||||||
import { mdiClose, mdiMenuDown, mdiMenuUp } from "@mdi/js";
 | 
					import { mdiClose, mdiMenuDown, mdiMenuUp } from "@mdi/js";
 | 
				
			||||||
import "@polymer/paper-input/paper-input";
 | 
					import "@polymer/paper-input/paper-input";
 | 
				
			||||||
import "@polymer/paper-item/paper-item";
 | 
					import "@polymer/paper-item/paper-item";
 | 
				
			||||||
@@ -14,13 +15,14 @@ import {
 | 
				
			|||||||
  query,
 | 
					  query,
 | 
				
			||||||
  TemplateResult,
 | 
					  TemplateResult,
 | 
				
			||||||
} from "lit-element";
 | 
					} from "lit-element";
 | 
				
			||||||
 | 
					import memoizeOne from "memoize-one";
 | 
				
			||||||
import { fireEvent } from "../../common/dom/fire_event";
 | 
					import { fireEvent } from "../../common/dom/fire_event";
 | 
				
			||||||
 | 
					import { computeDomain } from "../../common/entity/compute_domain";
 | 
				
			||||||
import { PolymerChangedEvent } from "../../polymer-types";
 | 
					import { PolymerChangedEvent } from "../../polymer-types";
 | 
				
			||||||
import { HomeAssistant } from "../../types";
 | 
					import { HomeAssistant } from "../../types";
 | 
				
			||||||
 | 
					import { formatAttributeName } from "../../util/hass-attributes-util";
 | 
				
			||||||
import "../ha-svg-icon";
 | 
					import "../ha-svg-icon";
 | 
				
			||||||
import "./state-badge";
 | 
					import "./state-badge";
 | 
				
			||||||
import { formatAttributeName } from "../../util/hass-attributes-util";
 | 
					 | 
				
			||||||
import "@material/mwc-icon-button/mwc-icon-button";
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type HaEntityPickerEntityFilterFunc = (entityId: HassEntity) => boolean;
 | 
					export type HaEntityPickerEntityFilterFunc = (entityId: HassEntity) => boolean;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -41,6 +43,41 @@ const rowRenderer = (root: HTMLElement, _owner, model: { item: string }) => {
 | 
				
			|||||||
  );
 | 
					  );
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const SELECTABLE_ATTRIBUTES: { [key: string]: string[] } = {
 | 
				
			||||||
 | 
					  light: ["brightness"],
 | 
				
			||||||
 | 
					  climate: [
 | 
				
			||||||
 | 
					    "current_temperature",
 | 
				
			||||||
 | 
					    "fan_mode",
 | 
				
			||||||
 | 
					    "preset_mode",
 | 
				
			||||||
 | 
					    "swing_mode",
 | 
				
			||||||
 | 
					    "temperature",
 | 
				
			||||||
 | 
					    "current_hundity",
 | 
				
			||||||
 | 
					    "humidity",
 | 
				
			||||||
 | 
					    "hvac_action",
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  fan: ["speed"],
 | 
				
			||||||
 | 
					  air_quality: [
 | 
				
			||||||
 | 
					    "nitrogen_oxide",
 | 
				
			||||||
 | 
					    "particulate_matter_10",
 | 
				
			||||||
 | 
					    "particulate_matter_2_5",
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  cover: ["current_position", "current_tilt_position"],
 | 
				
			||||||
 | 
					  device_tracker: ["battery"],
 | 
				
			||||||
 | 
					  humidifier: ["humidty"],
 | 
				
			||||||
 | 
					  media_player: ["media_title"],
 | 
				
			||||||
 | 
					  vacuum: ["battery_level", "status"],
 | 
				
			||||||
 | 
					  water_heater: ["current_temperature", "temperature", "operation_mode"],
 | 
				
			||||||
 | 
					  weather: [
 | 
				
			||||||
 | 
					    "temperature",
 | 
				
			||||||
 | 
					    "humidity",
 | 
				
			||||||
 | 
					    "ozone",
 | 
				
			||||||
 | 
					    "pressure",
 | 
				
			||||||
 | 
					    "wind_bearing",
 | 
				
			||||||
 | 
					    "wind_speed",
 | 
				
			||||||
 | 
					    "visibility",
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@customElement("ha-entity-attribute-picker")
 | 
					@customElement("ha-entity-attribute-picker")
 | 
				
			||||||
class HaEntityAttributePicker extends LitElement {
 | 
					class HaEntityAttributePicker extends LitElement {
 | 
				
			||||||
  @property({ attribute: false }) public hass!: HomeAssistant;
 | 
					  @property({ attribute: false }) public hass!: HomeAssistant;
 | 
				
			||||||
@@ -68,9 +105,8 @@ class HaEntityAttributePicker extends LitElement {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  protected updated(changedProps: PropertyValues) {
 | 
					  protected updated(changedProps: PropertyValues) {
 | 
				
			||||||
    if (changedProps.has("_opened") && this._opened) {
 | 
					    if (changedProps.has("_opened") && this._opened) {
 | 
				
			||||||
      const state = this.entityId ? this.hass.states[this.entityId] : undefined;
 | 
					      (this._comboBox as any).items = this.entityId
 | 
				
			||||||
      (this._comboBox as any).items = state
 | 
					        ? this._selectableAttributes(this.entityId)
 | 
				
			||||||
        ? Object.keys(state.attributes)
 | 
					 | 
				
			||||||
        : [];
 | 
					        : [];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -85,7 +121,6 @@ class HaEntityAttributePicker extends LitElement {
 | 
				
			|||||||
        .value=${this._value}
 | 
					        .value=${this._value}
 | 
				
			||||||
        .allowCustomValue=${this.allowCustomValue}
 | 
					        .allowCustomValue=${this.allowCustomValue}
 | 
				
			||||||
        .renderer=${rowRenderer}
 | 
					        .renderer=${rowRenderer}
 | 
				
			||||||
        attr-for-value="bind-value"
 | 
					 | 
				
			||||||
        @opened-changed=${this._openedChanged}
 | 
					        @opened-changed=${this._openedChanged}
 | 
				
			||||||
        @value-changed=${this._valueChanged}
 | 
					        @value-changed=${this._valueChanged}
 | 
				
			||||||
      >
 | 
					      >
 | 
				
			||||||
@@ -137,6 +172,17 @@ class HaEntityAttributePicker extends LitElement {
 | 
				
			|||||||
    `;
 | 
					    `;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private _selectableAttributes = memoizeOne((entity: string) => {
 | 
				
			||||||
 | 
					    const stateObj = this.hass.states[entity];
 | 
				
			||||||
 | 
					    if (!stateObj) {
 | 
				
			||||||
 | 
					      return [];
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return Object.keys(stateObj.attributes).filter((attr) =>
 | 
				
			||||||
 | 
					      SELECTABLE_ATTRIBUTES[computeDomain(entity)].includes(attr)
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private _clearValue(ev: Event) {
 | 
					  private _clearValue(ev: Event) {
 | 
				
			||||||
    ev.stopPropagation();
 | 
					    ev.stopPropagation();
 | 
				
			||||||
    this._setValue("");
 | 
					    this._setValue("");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -115,6 +115,7 @@ export class HuiEntityCardEditor extends LitElement
 | 
				
			|||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
        <div class="side-by-side">
 | 
					        <div class="side-by-side">
 | 
				
			||||||
          <ha-entity-attribute-picker
 | 
					          <ha-entity-attribute-picker
 | 
				
			||||||
 | 
					            allow-custom-value
 | 
				
			||||||
            .hass=${this.hass}
 | 
					            .hass=${this.hass}
 | 
				
			||||||
            .entityId=${this._entity}
 | 
					            .entityId=${this._entity}
 | 
				
			||||||
            .label="${this.hass.localize(
 | 
					            .label="${this.hass.localize(
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user