mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 15:26:36 +00:00
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:
parent
5ecde44243
commit
aa2641d5c9
@ -15,6 +15,14 @@ class HaEntityAttributePicker extends LitElement {
|
|||||||
|
|
||||||
@property() public entityId?: string;
|
@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 autofocus = false;
|
||||||
|
|
||||||
@property({ type: Boolean }) public disabled = false;
|
@property({ type: Boolean }) public disabled = false;
|
||||||
@ -42,7 +50,9 @@ class HaEntityAttributePicker extends LitElement {
|
|||||||
if (changedProps.has("_opened") && this._opened) {
|
if (changedProps.has("_opened") && this._opened) {
|
||||||
const state = this.entityId ? this.hass.states[this.entityId] : undefined;
|
const state = this.entityId ? this.hass.states[this.entityId] : undefined;
|
||||||
(this._comboBox as any).items = state
|
(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,
|
value: key,
|
||||||
label: formatAttributeName(key),
|
label: formatAttributeName(key),
|
||||||
}))
|
}))
|
||||||
|
@ -8,9 +8,9 @@ import "../entity/ha-entity-attribute-picker";
|
|||||||
|
|
||||||
@customElement("ha-selector-attribute")
|
@customElement("ha-selector-attribute")
|
||||||
export class HaSelectorAttribute extends SubscribeMixin(LitElement) {
|
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;
|
@property() public value?: any;
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ export class HaSelectorAttribute extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public required = true;
|
@property({ type: Boolean }) public required = true;
|
||||||
|
|
||||||
@property() public context?: {
|
@property({ attribute: false }) public context?: {
|
||||||
filter_entity?: string;
|
filter_entity?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -32,6 +32,7 @@ export class HaSelectorAttribute extends SubscribeMixin(LitElement) {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.entityId=${this.selector.attribute.entity_id ||
|
.entityId=${this.selector.attribute.entity_id ||
|
||||||
this.context?.filter_entity}
|
this.context?.filter_entity}
|
||||||
|
.excludeAttributes=${this.selector.attribute.exclude_attributes}
|
||||||
.value=${this.value}
|
.value=${this.value}
|
||||||
.label=${this.label}
|
.label=${this.label}
|
||||||
.helper=${this.helper}
|
.helper=${this.helper}
|
||||||
|
@ -65,6 +65,7 @@ export interface AreaSelector {
|
|||||||
export interface AttributeSelector {
|
export interface AttributeSelector {
|
||||||
attribute: {
|
attribute: {
|
||||||
entity_id?: string;
|
entity_id?: string;
|
||||||
|
exclude_attributes?: readonly string[];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import "../../../../../components/ha-form/ha-form";
|
|
||||||
import { html, LitElement } from "lit";
|
import { html, LitElement } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { fireEvent } from "../../../../../common/dom/fire_event";
|
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 { NumericStateCondition } from "../../../../../data/automation";
|
||||||
import type { HomeAssistant } from "../../../../../types";
|
import type { HomeAssistant } from "../../../../../types";
|
||||||
import type { SchemaUnion } from "../../../../../components/ha-form/types";
|
|
||||||
|
|
||||||
@customElement("ha-automation-condition-numeric_state")
|
@customElement("ha-automation-condition-numeric_state")
|
||||||
export default class HaNumericStateCondition extends LitElement {
|
export default class HaNumericStateCondition extends LitElement {
|
||||||
@ -25,7 +25,75 @@ export default class HaNumericStateCondition extends LitElement {
|
|||||||
{ name: "entity_id", required: true, selector: { entity: {} } },
|
{ name: "entity_id", required: true, selector: { entity: {} } },
|
||||||
{
|
{
|
||||||
name: "attribute",
|
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: "above", selector: { text: {} } },
|
||||||
{ name: "below", selector: { text: {} } },
|
{ name: "below", selector: { text: {} } },
|
||||||
|
@ -4,12 +4,12 @@ import memoizeOne from "memoize-one";
|
|||||||
import { assert, literal, object, optional, string, union } from "superstruct";
|
import { assert, literal, object, optional, string, union } from "superstruct";
|
||||||
import { createDurationData } from "../../../../../common/datetime/create_duration_data";
|
import { createDurationData } from "../../../../../common/datetime/create_duration_data";
|
||||||
import { fireEvent } from "../../../../../common/dom/fire_event";
|
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 { StateCondition } from "../../../../../data/automation";
|
||||||
import type { HomeAssistant } from "../../../../../types";
|
import type { HomeAssistant } from "../../../../../types";
|
||||||
import { forDictStruct } from "../../structs";
|
import { forDictStruct } from "../../structs";
|
||||||
import type { ConditionElement } from "../ha-automation-condition-row";
|
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({
|
const stateConditionStruct = object({
|
||||||
condition: literal("state"),
|
condition: literal("state"),
|
||||||
@ -35,7 +35,33 @@ export class HaStateCondition extends LitElement implements ConditionElement {
|
|||||||
{ name: "entity_id", required: true, selector: { entity: {} } },
|
{ name: "entity_id", required: true, selector: { entity: {} } },
|
||||||
{
|
{
|
||||||
name: "attribute",
|
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",
|
name: "state",
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
import "../../../../../components/ha-form/ha-form";
|
|
||||||
import { html, LitElement, PropertyValues } from "lit";
|
import { html, LitElement, PropertyValues } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { createDurationData } from "../../../../../common/datetime/create_duration_data";
|
import { createDurationData } from "../../../../../common/datetime/create_duration_data";
|
||||||
import { fireEvent } from "../../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../../common/dom/fire_event";
|
||||||
import { hasTemplate } from "../../../../../common/string/has-template";
|
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 { NumericStateTrigger } from "../../../../../data/automation";
|
||||||
import type { HomeAssistant } from "../../../../../types";
|
import type { HomeAssistant } from "../../../../../types";
|
||||||
import type { SchemaUnion } from "../../../../../components/ha-form/types";
|
|
||||||
|
|
||||||
@customElement("ha-automation-trigger-numeric_state")
|
@customElement("ha-automation-trigger-numeric_state")
|
||||||
export class HaNumericStateTrigger extends LitElement {
|
export class HaNumericStateTrigger extends LitElement {
|
||||||
@ -21,7 +21,75 @@ export class HaNumericStateTrigger extends LitElement {
|
|||||||
{ name: "entity_id", required: true, selector: { entity: {} } },
|
{ name: "entity_id", required: true, selector: { entity: {} } },
|
||||||
{
|
{
|
||||||
name: "attribute",
|
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: "above", selector: { text: {} } },
|
||||||
{ name: "below", selector: { text: {} } },
|
{ name: "below", selector: { text: {} } },
|
||||||
|
@ -55,7 +55,35 @@ export class HaStateTrigger extends LitElement implements TriggerElement {
|
|||||||
{
|
{
|
||||||
name: "attribute",
|
name: "attribute",
|
||||||
selector: {
|
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",
|
||||||
|
],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user