From 961ca96435ff7fd65bf6e2b7b6da61bf7ed58ced Mon Sep 17 00:00:00 2001 From: karwosts Date: Sat, 28 Sep 2024 06:30:22 -0700 Subject: [PATCH] Allow override entity_id in more-info action --- src/data/lovelace/config/action.ts | 1 + src/panels/lovelace/common/handle-action.ts | 13 +++++++------ src/panels/lovelace/editor/structs/action-struct.ts | 8 ++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/data/lovelace/config/action.ts b/src/data/lovelace/config/action.ts index 9ed065bc8dcd..800a54dc3f28 100644 --- a/src/data/lovelace/config/action.ts +++ b/src/data/lovelace/config/action.ts @@ -28,6 +28,7 @@ export interface UrlActionConfig extends BaseActionConfig { export interface MoreInfoActionConfig extends BaseActionConfig { action: "more-info"; + entity_id?: string; } export interface AssistActionConfig extends BaseActionConfig { diff --git a/src/panels/lovelace/common/handle-action.ts b/src/panels/lovelace/common/handle-action.ts index 609e0c162ba6..3c51b0d46861 100644 --- a/src/panels/lovelace/common/handle-action.ts +++ b/src/panels/lovelace/common/handle-action.ts @@ -94,12 +94,13 @@ export const handleAction = async ( switch (actionConfig.action) { case "more-info": { - if (config.entity || config.camera_image || config.image_entity) { - fireEvent(node, "hass-more-info", { - entityId: (config.entity || - config.camera_image || - config.image_entity)!, - }); + const entityId = + actionConfig.entity_id || + config.entity || + config.camera_image || + config.image_entity; + if (entityId) { + fireEvent(node, "hass-more-info", { entityId }); } else { showToast(node, { message: hass.localize( diff --git a/src/panels/lovelace/editor/structs/action-struct.ts b/src/panels/lovelace/editor/structs/action-struct.ts index 75ff88bebaf2..d1f8d90c483a 100644 --- a/src/panels/lovelace/editor/structs/action-struct.ts +++ b/src/panels/lovelace/editor/structs/action-struct.ts @@ -61,6 +61,11 @@ const actionConfigStructAssist = type({ start_listening: optional(boolean()), }); +const actionConfigStructMoreInfo = type({ + action: literal("more-info"), + entity_id: optional(string()), +}); + export const actionConfigStructType = object({ action: enums([ "none", @@ -93,6 +98,9 @@ export const actionConfigStruct = dynamic((value) => { case "assist": { return actionConfigStructAssist; } + case "more-info": { + return actionConfigStructMoreInfo; + } } }