mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 17:26:42 +00:00
Unused entities to respect tap/hold action (#2754)
This commit is contained in:
parent
c570ce9720
commit
ac179f5b45
@ -5,7 +5,6 @@ export interface LovelaceConfig {
|
|||||||
views: LovelaceViewConfig[];
|
views: LovelaceViewConfig[];
|
||||||
background?: string;
|
background?: string;
|
||||||
resources?: Array<{ type: "css" | "js" | "module" | "html"; url: string }>;
|
resources?: Array<{ type: "css" | "js" | "module" | "html"; url: string }>;
|
||||||
excluded_entities?: string[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LovelaceViewConfig {
|
export interface LovelaceViewConfig {
|
||||||
@ -34,7 +33,10 @@ export interface ToggleActionConfig {
|
|||||||
export interface CallServiceActionConfig {
|
export interface CallServiceActionConfig {
|
||||||
action: "call-service";
|
action: "call-service";
|
||||||
service: string;
|
service: string;
|
||||||
service_data?: { [key: string]: any };
|
service_data?: {
|
||||||
|
entity_id?: string | [string];
|
||||||
|
[key: string]: any;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NavigateActionConfig {
|
export interface NavigateActionConfig {
|
||||||
|
@ -1,38 +1,66 @@
|
|||||||
import { LovelaceConfig } from "../../../data/lovelace";
|
import { LovelaceConfig, ActionConfig } from "../../../data/lovelace";
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
|
|
||||||
const EXCLUDED_DOMAINS = ["zone"];
|
const EXCLUDED_DOMAINS = ["zone"];
|
||||||
|
|
||||||
|
const addFromAction = (entities: Set<string>, actionConfig: ActionConfig) => {
|
||||||
|
if (
|
||||||
|
actionConfig.action !== "call-service" ||
|
||||||
|
!actionConfig.service_data ||
|
||||||
|
!actionConfig.service_data.entity_id
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let entityIds = actionConfig.service_data.entity_id;
|
||||||
|
if (!Array.isArray(entityIds)) {
|
||||||
|
entityIds = [entityIds];
|
||||||
|
}
|
||||||
|
for (const entityId of entityIds) {
|
||||||
|
entities.add(entityId);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const addEntityId = (entities: Set<string>, entity) => {
|
||||||
|
if (typeof entity === "string") {
|
||||||
|
entities.add(entity);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity.entity) {
|
||||||
|
entities.add(entity.entity);
|
||||||
|
}
|
||||||
|
if (entity.camera_image) {
|
||||||
|
entities.add(entity.camera_image);
|
||||||
|
}
|
||||||
|
if (entity.tap_action) {
|
||||||
|
addFromAction(entities, entity.tap_action);
|
||||||
|
}
|
||||||
|
if (entity.hold_action) {
|
||||||
|
addFromAction(entities, entity.hold_action);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const addEntities = (entities: Set<string>, obj) => {
|
||||||
|
if (obj.entity) {
|
||||||
|
addEntityId(entities, obj.entity);
|
||||||
|
}
|
||||||
|
if (obj.entities) {
|
||||||
|
obj.entities.forEach((entity) => addEntityId(entities, entity));
|
||||||
|
}
|
||||||
|
if (obj.card) {
|
||||||
|
addEntities(entities, obj.card);
|
||||||
|
}
|
||||||
|
if (obj.cards) {
|
||||||
|
obj.cards.forEach((card) => addEntities(entities, card));
|
||||||
|
}
|
||||||
|
if (obj.badges) {
|
||||||
|
obj.badges.forEach((badge) => addEntityId(entities, badge));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const computeUsedEntities = (config) => {
|
const computeUsedEntities = (config) => {
|
||||||
const entities = new Set();
|
const entities = new Set();
|
||||||
|
config.views.forEach((view) => addEntities(entities, view));
|
||||||
const addEntityId = (entity) => {
|
|
||||||
if (typeof entity === "string") {
|
|
||||||
entities.add(entity);
|
|
||||||
} else if (entity.entity) {
|
|
||||||
entities.add(entity.entity);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const addEntities = (obj) => {
|
|
||||||
if (obj.entity) {
|
|
||||||
addEntityId(obj.entity);
|
|
||||||
}
|
|
||||||
if (obj.entities) {
|
|
||||||
obj.entities.forEach((entity) => addEntityId(entity));
|
|
||||||
}
|
|
||||||
if (obj.card) {
|
|
||||||
addEntities(obj.card);
|
|
||||||
}
|
|
||||||
if (obj.cards) {
|
|
||||||
obj.cards.forEach((card) => addEntities(card));
|
|
||||||
}
|
|
||||||
if (obj.badges) {
|
|
||||||
obj.badges.forEach((badge) => addEntityId(badge));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
config.views.forEach((view) => addEntities(view));
|
|
||||||
return entities;
|
return entities;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -45,9 +73,6 @@ export const computeUnusedEntities = (
|
|||||||
.filter(
|
.filter(
|
||||||
(entity) =>
|
(entity) =>
|
||||||
!usedEntities.has(entity) &&
|
!usedEntities.has(entity) &&
|
||||||
!(
|
|
||||||
config.excluded_entities && config.excluded_entities.includes(entity)
|
|
||||||
) &&
|
|
||||||
!EXCLUDED_DOMAINS.includes(entity.split(".", 1)[0])
|
!EXCLUDED_DOMAINS.includes(entity.split(".", 1)[0])
|
||||||
)
|
)
|
||||||
.sort();
|
.sort();
|
||||||
|
@ -33,7 +33,7 @@ export const handleClick = (
|
|||||||
case "more-info":
|
case "more-info":
|
||||||
if (config.entity || config.camera_image) {
|
if (config.entity || config.camera_image) {
|
||||||
fireEvent(node, "hass-more-info", {
|
fireEvent(node, "hass-more-info", {
|
||||||
entityId: config.entity ? config.entity! : config.camera_image!,
|
entityId: config.entity ? config.entity : config.camera_image!,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -64,7 +64,7 @@ export class HuiUnusedEntities extends LitElement {
|
|||||||
hui-entities-card {
|
hui-entities-card {
|
||||||
max-width: 400px;
|
max-width: 400px;
|
||||||
padding: 4px;
|
padding: 4px;
|
||||||
flex: 1;
|
flex: 1 auto;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
`;
|
`;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user