mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 16:26:43 +00:00
Exclude entities in controls for areas dashboard (#25906)
This commit is contained in:
parent
9afc4260c9
commit
f90eb4fee0
@ -67,18 +67,20 @@ export const supportsAreaControlsCardFeature = (
|
|||||||
export const getAreaControlEntities = (
|
export const getAreaControlEntities = (
|
||||||
controls: AreaControl[],
|
controls: AreaControl[],
|
||||||
areaId: string,
|
areaId: string,
|
||||||
hass: HomeAssistant
|
hass: HomeAssistant,
|
||||||
|
excludeEntities: string[] = []
|
||||||
): Record<AreaControl, string[]> =>
|
): Record<AreaControl, string[]> =>
|
||||||
controls.reduce(
|
controls.reduce(
|
||||||
(acc, control) => {
|
(acc, control) => {
|
||||||
const controlButton = AREA_CONTROLS_BUTTONS[control];
|
const controlButton = AREA_CONTROLS_BUTTONS[control];
|
||||||
const filter = generateEntityFilter(hass, {
|
const filter = generateEntityFilter(hass, {
|
||||||
area: areaId,
|
area: areaId,
|
||||||
|
entity_category: "none",
|
||||||
...controlButton.filter,
|
...controlButton.filter,
|
||||||
});
|
});
|
||||||
|
|
||||||
acc[control] = Object.keys(hass.entities).filter((entityId) =>
|
acc[control] = Object.keys(hass.entities).filter(
|
||||||
filter(entityId)
|
(entityId) => filter(entityId) && !excludeEntities.includes(entityId)
|
||||||
);
|
);
|
||||||
return acc;
|
return acc;
|
||||||
},
|
},
|
||||||
@ -134,7 +136,7 @@ class HuiAreaControlsCardFeature
|
|||||||
private _handleButtonTap(ev: MouseEvent) {
|
private _handleButtonTap(ev: MouseEvent) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
|
|
||||||
if (!this.context?.area_id || !this.hass) {
|
if (!this.context?.area_id || !this.hass || !this._config) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const control = (ev.currentTarget as any).control as AreaControl;
|
const control = (ev.currentTarget as any).control as AreaControl;
|
||||||
@ -142,6 +144,7 @@ class HuiAreaControlsCardFeature
|
|||||||
const controlEntities = this._controlEntities(
|
const controlEntities = this._controlEntities(
|
||||||
this._controls,
|
this._controls,
|
||||||
this.context.area_id,
|
this.context.area_id,
|
||||||
|
this._config.exclude_entities,
|
||||||
this.hass!.entities,
|
this.hass!.entities,
|
||||||
this.hass!.devices,
|
this.hass!.devices,
|
||||||
this.hass!.areas
|
this.hass!.areas
|
||||||
@ -165,11 +168,12 @@ class HuiAreaControlsCardFeature
|
|||||||
(
|
(
|
||||||
controls: AreaControl[],
|
controls: AreaControl[],
|
||||||
areaId: string,
|
areaId: string,
|
||||||
|
excludeEntities: string[] | undefined,
|
||||||
// needed to update memoized function when entities, devices or areas change
|
// needed to update memoized function when entities, devices or areas change
|
||||||
_entities: HomeAssistant["entities"],
|
_entities: HomeAssistant["entities"],
|
||||||
_devices: HomeAssistant["devices"],
|
_devices: HomeAssistant["devices"],
|
||||||
_areas: HomeAssistant["areas"]
|
_areas: HomeAssistant["areas"]
|
||||||
) => getAreaControlEntities(controls, areaId, this.hass!)
|
) => getAreaControlEntities(controls, areaId, this.hass!, excludeEntities)
|
||||||
);
|
);
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
@ -186,6 +190,7 @@ class HuiAreaControlsCardFeature
|
|||||||
const controlEntities = this._controlEntities(
|
const controlEntities = this._controlEntities(
|
||||||
this._controls,
|
this._controls,
|
||||||
this.context.area_id!,
|
this.context.area_id!,
|
||||||
|
this._config.exclude_entities,
|
||||||
this.hass!.entities,
|
this.hass!.entities,
|
||||||
this.hass!.devices,
|
this.hass!.devices,
|
||||||
this.hass!.areas
|
this.hass!.areas
|
||||||
|
@ -165,6 +165,7 @@ export type AreaControl = (typeof AREA_CONTROLS)[number];
|
|||||||
export interface AreaControlsCardFeatureConfig {
|
export interface AreaControlsCardFeatureConfig {
|
||||||
type: "area-controls";
|
type: "area-controls";
|
||||||
controls?: AreaControl[];
|
controls?: AreaControl[];
|
||||||
|
exclude_entities?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type LovelaceCardFeatureConfig =
|
export type LovelaceCardFeatureConfig =
|
||||||
|
@ -71,11 +71,18 @@ export class AreasOverviewViewStrategy extends ReactiveElement {
|
|||||||
const areasCards = areasInFloors.map<AreaCardConfig>((area) => {
|
const areasCards = areasInFloors.map<AreaCardConfig>((area) => {
|
||||||
const path = computeAreaPath(area.area_id);
|
const path = computeAreaPath(area.area_id);
|
||||||
|
|
||||||
|
const areaOptions = config.areas_options?.[area.area_id] || {};
|
||||||
|
|
||||||
|
const hiddenEntities = Object.values(areaOptions.groups_options || {})
|
||||||
|
.map((display) => display.hidden || [])
|
||||||
|
.flat();
|
||||||
|
|
||||||
const controls: AreaControl[] = ["light", "fan"];
|
const controls: AreaControl[] = ["light", "fan"];
|
||||||
const controlEntities = getAreaControlEntities(
|
const controlEntities = getAreaControlEntities(
|
||||||
controls,
|
controls,
|
||||||
area.area_id,
|
area.area_id,
|
||||||
hass
|
hass,
|
||||||
|
hiddenEntities
|
||||||
);
|
);
|
||||||
|
|
||||||
const filteredControls = controls.filter(
|
const filteredControls = controls.filter(
|
||||||
@ -101,6 +108,7 @@ export class AreasOverviewViewStrategy extends ReactiveElement {
|
|||||||
{
|
{
|
||||||
type: "area-controls",
|
type: "area-controls",
|
||||||
controls: filteredControls,
|
controls: filteredControls,
|
||||||
|
exclude_entities: hiddenEntities,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
: [],
|
: [],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user