mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-26 02:36:37 +00:00
Don't use combine mode
This commit is contained in:
parent
ea5c014552
commit
06f653117a
@ -16,8 +16,6 @@ interface StateOption {
|
|||||||
label: string;
|
label: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_COMBINE_MODE: "union" | "intersection" = "union";
|
|
||||||
|
|
||||||
@customElement("ha-entity-state-picker")
|
@customElement("ha-entity-state-picker")
|
||||||
class HaEntityStatePicker extends LitElement {
|
class HaEntityStatePicker extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
@ -41,9 +39,6 @@ class HaEntityStatePicker extends LitElement {
|
|||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
public hideStates?: string[];
|
public hideStates?: string[];
|
||||||
|
|
||||||
@property({ attribute: "combine-mode" })
|
|
||||||
public combineMode?: "union" | "intersection";
|
|
||||||
|
|
||||||
@property() public label?: string;
|
@property() public label?: string;
|
||||||
|
|
||||||
@property() public value?: string;
|
@property() public value?: string;
|
||||||
@ -74,47 +69,25 @@ class HaEntityStatePicker extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const states = getStates(this.hass, stateObj, this.attribute).filter(
|
const states = getStates(this.hass, stateObj, this.attribute).filter(
|
||||||
(s) => !this.hideStates || !this.hideStates.includes(s)
|
(s) => !this.hideStates?.includes(s)
|
||||||
);
|
);
|
||||||
|
|
||||||
return states.map((s) => ({
|
return states.map((s) => ({
|
||||||
value: s,
|
value: s,
|
||||||
label: !this.attribute
|
label: this.attribute
|
||||||
? this.hass.formatEntityState(stateObj, s)
|
? this.hass.formatEntityAttributeValue(stateObj, this.attribute, s)
|
||||||
: this.hass.formatEntityAttributeValue(stateObj, this.attribute, s),
|
: this.hass.formatEntityState(stateObj, s),
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
const mode: "union" | "intersection" =
|
const options: StateOption[] = [];
|
||||||
this.combineMode || DEFAULT_COMBINE_MODE;
|
const optionsSet = new Set<string>();
|
||||||
|
for (const entityOptions of entitiesOptions) {
|
||||||
let options: StateOption[] = [];
|
for (const option of entityOptions) {
|
||||||
|
if (!optionsSet.has(option.value)) {
|
||||||
if (mode === "union") {
|
optionsSet.add(option.value);
|
||||||
// Union: combine all unique states from all entities
|
options.push(option);
|
||||||
options = entitiesOptions.reduce(
|
}
|
||||||
(acc, curr) => [
|
|
||||||
...acc,
|
|
||||||
...curr.filter(
|
|
||||||
(item) => !acc.some((existing) => existing.value === item.value)
|
|
||||||
),
|
|
||||||
],
|
|
||||||
[] as StateOption[]
|
|
||||||
);
|
|
||||||
} else if (mode === "intersection") {
|
|
||||||
// Intersection: only states that exist in ALL entities
|
|
||||||
if (entitiesOptions.length === 0) {
|
|
||||||
options = [];
|
|
||||||
} else if (entitiesOptions.length === 1) {
|
|
||||||
options = entitiesOptions[0];
|
|
||||||
} else {
|
|
||||||
options = entitiesOptions[0].filter((item) =>
|
|
||||||
entitiesOptions
|
|
||||||
.slice(1)
|
|
||||||
.every((entityOptions) =>
|
|
||||||
entityOptions.some((option) => option.value === item.value)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,6 @@ export class HaSelectorState extends SubscribeMixin(LitElement) {
|
|||||||
.required=${this.required}
|
.required=${this.required}
|
||||||
allow-custom-value
|
allow-custom-value
|
||||||
.hideStates=${this.selector.state?.hide_states}
|
.hideStates=${this.selector.state?.hide_states}
|
||||||
.combineMode=${this.selector.state?.combine_mode}
|
|
||||||
></ha-entity-state-picker>
|
></ha-entity-state-picker>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
@ -55,20 +55,6 @@ const showOptionalToggle = (field) =>
|
|||||||
!field.required &&
|
!field.required &&
|
||||||
!("boolean" in field.selector && field.default);
|
!("boolean" in field.selector && field.default);
|
||||||
|
|
||||||
const enrichSelector = (selector: Selector): Selector => {
|
|
||||||
// Default combine_mode to intersection for state selectors
|
|
||||||
if ("state" in selector) {
|
|
||||||
return {
|
|
||||||
...selector,
|
|
||||||
state: {
|
|
||||||
...selector.state,
|
|
||||||
combine_mode: selector.state?.combine_mode || "intersection",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return selector;
|
|
||||||
};
|
|
||||||
|
|
||||||
interface Field extends Omit<HassService["fields"][string], "selector"> {
|
interface Field extends Omit<HassService["fields"][string], "selector"> {
|
||||||
key: string;
|
key: string;
|
||||||
selector?: Selector;
|
selector?: Selector;
|
||||||
@ -258,9 +244,7 @@ export class HaServiceControl extends LitElement {
|
|||||||
).map(([key, value]) => ({
|
).map(([key, value]) => ({
|
||||||
key,
|
key,
|
||||||
...value,
|
...value,
|
||||||
selector: (value.selector
|
selector: (value.selector || undefined) as Selector | undefined,
|
||||||
? enrichSelector(value.selector)
|
|
||||||
: undefined) as Selector | undefined,
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const flatFields: Field[] = [];
|
const flatFields: Field[] = [];
|
||||||
|
@ -396,7 +396,6 @@ export interface StateSelector {
|
|||||||
entity_id?: string | string[];
|
entity_id?: string | string[];
|
||||||
attribute?: string;
|
attribute?: string;
|
||||||
hide_states?: string[];
|
hide_states?: string[];
|
||||||
combine_mode?: "union" | "intersection";
|
|
||||||
} | null;
|
} | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user