Skip to content

Commit

Permalink
Allow override entity_id in more-info action
Browse files Browse the repository at this point in the history
  • Loading branch information
karwosts committed Sep 28, 2024
1 parent 5d71d4c commit 961ca96
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/data/lovelace/config/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 7 additions & 6 deletions src/panels/lovelace/common/handle-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 8 additions & 0 deletions src/panels/lovelace/editor/structs/action-struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -93,6 +98,9 @@ export const actionConfigStruct = dynamic<any>((value) => {
case "assist": {
return actionConfigStructAssist;
}
case "more-info": {
return actionConfigStructMoreInfo;
}
}
}

Expand Down

0 comments on commit 961ca96

Please sign in to comment.