Improve context support

This commit is contained in:
Paul Bottein 2025-07-17 14:33:33 +02:00
parent 81870d0e7d
commit be71c0b4fa
No known key found for this signature in database
2 changed files with 7 additions and 12 deletions

View File

@ -627,7 +627,7 @@ export class HaServiceControl extends LitElement {
const fieldDataHasTemplate =
this._value?.data && hasTemplate(this._value.data[dataField.key]);
let selector =
const selector =
fieldDataHasTemplate &&
typeof this._value!.data![dataField.key] === "string"
? { template: null }
@ -637,16 +637,6 @@ export class HaServiceControl extends LitElement {
: (this._stickySelector[dataField.key] ??
dataField?.selector ?? { text: null });
if ("state" in selector) {
selector = {
...selector,
state: {
...selector.state,
entity_id: targetEntities || undefined,
},
};
}
if (fieldDataHasTemplate) {
// Hold this selector type until the field is cleared
this._stickySelector[dataField.key] = selector;
@ -685,6 +675,7 @@ export class HaServiceControl extends LitElement {
) || dataField?.description}</span
>
<ha-selector
.context=${this._selectorContext(targetEntities)}
.disabled=${this.disabled ||
(showOptional &&
!this._checkedKeys.has(dataField.key) &&
@ -704,6 +695,10 @@ export class HaServiceControl extends LitElement {
: "";
};
private _selectorContext = memoizeOne((targetEntities: string[] | null) => ({
filter_entity: targetEntities || undefined,
}));
private _localizeValueCallback = (key: string) => {
if (!this._value?.action) {
return "";

View File

@ -98,7 +98,7 @@ export interface AreasDisplaySelector {
export interface AttributeSelector {
attribute: {
entity_id?: string;
entity_id?: string | string[];
hide_attributes?: readonly string[];
} | null;
}