mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 01:06:35 +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[];
|
||||
background?: string;
|
||||
resources?: Array<{ type: "css" | "js" | "module" | "html"; url: string }>;
|
||||
excluded_entities?: string[];
|
||||
}
|
||||
|
||||
export interface LovelaceViewConfig {
|
||||
@ -34,7 +33,10 @@ export interface ToggleActionConfig {
|
||||
export interface CallServiceActionConfig {
|
||||
action: "call-service";
|
||||
service: string;
|
||||
service_data?: { [key: string]: any };
|
||||
service_data?: {
|
||||
entity_id?: string | [string];
|
||||
[key: string]: any;
|
||||
};
|
||||
}
|
||||
|
||||
export interface NavigateActionConfig {
|
||||
|
@ -1,38 +1,66 @@
|
||||
import { LovelaceConfig } from "../../../data/lovelace";
|
||||
import { LovelaceConfig, ActionConfig } from "../../../data/lovelace";
|
||||
import { HomeAssistant } from "../../../types";
|
||||
|
||||
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 entities = new Set();
|
||||
|
||||
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));
|
||||
config.views.forEach((view) => addEntities(entities, view));
|
||||
return entities;
|
||||
};
|
||||
|
||||
@ -45,9 +73,6 @@ export const computeUnusedEntities = (
|
||||
.filter(
|
||||
(entity) =>
|
||||
!usedEntities.has(entity) &&
|
||||
!(
|
||||
config.excluded_entities && config.excluded_entities.includes(entity)
|
||||
) &&
|
||||
!EXCLUDED_DOMAINS.includes(entity.split(".", 1)[0])
|
||||
)
|
||||
.sort();
|
||||
|
@ -33,7 +33,7 @@ export const handleClick = (
|
||||
case "more-info":
|
||||
if (config.entity || config.camera_image) {
|
||||
fireEvent(node, "hass-more-info", {
|
||||
entityId: config.entity ? config.entity! : config.camera_image!,
|
||||
entityId: config.entity ? config.entity : config.camera_image!,
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
@ -64,7 +64,7 @@ export class HuiUnusedEntities extends LitElement {
|
||||
hui-entities-card {
|
||||
max-width: 400px;
|
||||
padding: 4px;
|
||||
flex: 1;
|
||||
flex: 1 auto;
|
||||
}
|
||||
</style>
|
||||
`;
|
||||
|
Loading…
x
Reference in New Issue
Block a user