Add exclude attributes support to attribute selector (#13421)

* Add exclude attribute support to attribute selector

* Fix typing

* Fix rebase f-up

* Revert const removal

* Make exclude_attributes readonly and fix some propert mismatches

Co-authored-by: Zack <zackbarett@hey.com>
Co-authored-by: Steve Repsher <steverep@users.noreply.github.com>
This commit is contained in:
Franck Nijhof 2022-08-20 20:54:42 +02:00 committed by GitHub
parent 5ecde44243
commit aa2641d5c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 219 additions and 17 deletions

View File

@ -15,6 +15,14 @@ class HaEntityAttributePicker extends LitElement {
@property() public entityId?: string;
/**
* List of attributes to be excluded.
* @type {Array}
* @attr exclude-attributes
*/
@property({ type: Array, attribute: "exclude-attributes" })
public excludeAttributes?: string[];
@property({ type: Boolean }) public autofocus = false;
@property({ type: Boolean }) public disabled = false;
@ -42,7 +50,9 @@ class HaEntityAttributePicker extends LitElement {
if (changedProps.has("_opened") && this._opened) {
const state = this.entityId ? this.hass.states[this.entityId] : undefined;
(this._comboBox as any).items = state
? Object.keys(state.attributes).map((key) => ({
? Object.keys(state.attributes)
.filter((key) => !this.excludeAttributes?.includes(key))
.map((key) => ({
value: key,
label: formatAttributeName(key),
}))

View File

@ -8,9 +8,9 @@ import "../entity/ha-entity-attribute-picker";
@customElement("ha-selector-attribute")
export class HaSelectorAttribute extends SubscribeMixin(LitElement) {
@property() public hass!: HomeAssistant;
@property({ attribute: false }) public hass!: HomeAssistant;
@property() public selector!: AttributeSelector;
@property({ attribute: false }) public selector!: AttributeSelector;
@property() public value?: any;
@ -22,7 +22,7 @@ export class HaSelectorAttribute extends SubscribeMixin(LitElement) {
@property({ type: Boolean }) public required = true;
@property() public context?: {
@property({ attribute: false }) public context?: {
filter_entity?: string;
};
@ -32,6 +32,7 @@ export class HaSelectorAttribute extends SubscribeMixin(LitElement) {
.hass=${this.hass}
.entityId=${this.selector.attribute.entity_id ||
this.context?.filter_entity}
.excludeAttributes=${this.selector.attribute.exclude_attributes}
.value=${this.value}
.label=${this.label}
.helper=${this.helper}

View File

@ -65,6 +65,7 @@ export interface AreaSelector {
export interface AttributeSelector {
attribute: {
entity_id?: string;
exclude_attributes?: readonly string[];
};
}

View File

@ -1,11 +1,11 @@
import "../../../../../components/ha-form/ha-form";
import { html, LitElement } from "lit";
import { customElement, property } from "lit/decorators";
import memoizeOne from "memoize-one";
import { fireEvent } from "../../../../../common/dom/fire_event";
import "../../../../../components/ha-form/ha-form";
import type { SchemaUnion } from "../../../../../components/ha-form/types";
import { NumericStateCondition } from "../../../../../data/automation";
import type { HomeAssistant } from "../../../../../types";
import type { SchemaUnion } from "../../../../../components/ha-form/types";
@customElement("ha-automation-condition-numeric_state")
export default class HaNumericStateCondition extends LitElement {
@ -25,7 +25,75 @@ export default class HaNumericStateCondition extends LitElement {
{ name: "entity_id", required: true, selector: { entity: {} } },
{
name: "attribute",
selector: { attribute: { entity_id: entityId } },
selector: {
attribute: {
entity_id: entityId,
exclude_attributes: [
"access_token",
"auto_update",
"available_modes",
"away_mode",
"changed_by",
"code_format",
"color_modes",
"current_activity",
"device_class",
"editable",
"effect_list",
"effect",
"entity_picture",
"fan_mode",
"fan_modes",
"fan_speed_list",
"forecast",
"friendly_name",
"frontend_stream_type",
"has_date",
"has_time",
"hs_color",
"hvac_mode",
"hvac_modes",
"icon",
"media_album_name",
"media_artist",
"media_content_type",
"media_position_updated_at",
"media_title",
"next_dawn",
"next_dusk",
"next_midnight",
"next_noon",
"next_rising",
"next_setting",
"operation_list",
"operation_mode",
"options",
"preset_mode",
"preset_modes",
"release_notes",
"release_summary",
"release_url",
"restored",
"rgb_color",
"rgbw_color",
"shuffle",
"sound_mode_list",
"sound_mode",
"source_list",
"source_type",
"source",
"state_class",
"supported_features",
"swing_mode",
"swing_mode",
"swing_modes",
"title",
"token",
"unit_of_measurement",
"xy_color",
],
},
},
},
{ name: "above", selector: { text: {} } },
{ name: "below", selector: { text: {} } },

View File

@ -4,12 +4,12 @@ import memoizeOne from "memoize-one";
import { assert, literal, object, optional, string, union } from "superstruct";
import { createDurationData } from "../../../../../common/datetime/create_duration_data";
import { fireEvent } from "../../../../../common/dom/fire_event";
import "../../../../../components/ha-form/ha-form";
import type { SchemaUnion } from "../../../../../components/ha-form/types";
import type { StateCondition } from "../../../../../data/automation";
import type { HomeAssistant } from "../../../../../types";
import { forDictStruct } from "../../structs";
import type { ConditionElement } from "../ha-automation-condition-row";
import "../../../../../components/ha-form/ha-form";
import type { SchemaUnion } from "../../../../../components/ha-form/types";
const stateConditionStruct = object({
condition: literal("state"),
@ -35,7 +35,33 @@ export class HaStateCondition extends LitElement implements ConditionElement {
{ name: "entity_id", required: true, selector: { entity: {} } },
{
name: "attribute",
selector: { attribute: { entity_id: entityId } },
selector: {
attribute: {
entity_id: entityId,
exclude_attributes: [
"access_token",
"available_modes",
"color_modes",
"editable",
"effect_list",
"entity_picture",
"fan_modes",
"fan_speed_list",
"forecast",
"friendly_name",
"hvac_modes",
"icon",
"operation_list",
"options",
"preset_modes",
"sound_mode_list",
"source_list",
"state_class",
"swing_modes",
"token",
],
},
},
},
{
name: "state",

View File

@ -1,13 +1,13 @@
import "../../../../../components/ha-form/ha-form";
import { html, LitElement, PropertyValues } from "lit";
import { customElement, property } from "lit/decorators";
import memoizeOne from "memoize-one";
import { createDurationData } from "../../../../../common/datetime/create_duration_data";
import { fireEvent } from "../../../../../common/dom/fire_event";
import { hasTemplate } from "../../../../../common/string/has-template";
import "../../../../../components/ha-form/ha-form";
import type { SchemaUnion } from "../../../../../components/ha-form/types";
import type { NumericStateTrigger } from "../../../../../data/automation";
import type { HomeAssistant } from "../../../../../types";
import type { SchemaUnion } from "../../../../../components/ha-form/types";
@customElement("ha-automation-trigger-numeric_state")
export class HaNumericStateTrigger extends LitElement {
@ -21,7 +21,75 @@ export class HaNumericStateTrigger extends LitElement {
{ name: "entity_id", required: true, selector: { entity: {} } },
{
name: "attribute",
selector: { attribute: { entity_id: entityId } },
selector: {
attribute: {
entity_id: entityId,
exclude_attributes: [
"access_token",
"auto_update",
"available_modes",
"away_mode",
"changed_by",
"code_format",
"color_modes",
"current_activity",
"device_class",
"editable",
"effect_list",
"effect",
"entity_picture",
"fan_mode",
"fan_modes",
"fan_speed_list",
"forecast",
"friendly_name",
"frontend_stream_type",
"has_date",
"has_time",
"hs_color",
"hvac_mode",
"hvac_modes",
"icon",
"media_album_name",
"media_artist",
"media_content_type",
"media_position_updated_at",
"media_title",
"next_dawn",
"next_dusk",
"next_midnight",
"next_noon",
"next_rising",
"next_setting",
"operation_list",
"operation_mode",
"options",
"preset_mode",
"preset_modes",
"release_notes",
"release_summary",
"release_url",
"restored",
"rgb_color",
"rgbw_color",
"shuffle",
"sound_mode_list",
"sound_mode",
"source_list",
"source_type",
"source",
"state_class",
"supported_features",
"swing_mode",
"swing_mode",
"swing_modes",
"title",
"token",
"unit_of_measurement",
"xy_color",
],
},
},
},
{ name: "above", selector: { text: {} } },
{ name: "below", selector: { text: {} } },

View File

@ -55,7 +55,35 @@ export class HaStateTrigger extends LitElement implements TriggerElement {
{
name: "attribute",
selector: {
attribute: { entity_id: entityId ? entityId[0] : undefined },
attribute: {
entity_id: entityId ? entityId[0] : undefined,
exclude_attributes: [
"access_token",
"available_modes",
"color_modes",
"device_class",
"editable",
"effect_list",
"entity_picture",
"fan_modes",
"fan_speed_list",
"friendly_name",
"has_date",
"has_time",
"hvac_modes",
"icon",
"operation_list",
"options",
"preset_modes",
"sound_mode_list",
"source_list",
"state_class",
"supported_features",
"swing_modes",
"token",
"unit_of_measurement",
],
},
},
},
{