Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions src/panels/lovelace/common/compute-tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ interface Config extends LovelaceElementConfig {
}

export const computeTooltip = (hass: HomeAssistant, config: Config): string => {
if (config.title === null) {
return "";
}

if (config.title) {
return config.title;
}
Expand All @@ -26,10 +30,10 @@ export const computeTooltip = (hass: HomeAssistant, config: Config): string => {
}

const tapTooltip = config.tap_action
? computeActionTooltip(stateName, config.tap_action, false)
? computeActionTooltip(hass, stateName, config.tap_action, false)
: "";
const holdTooltip = config.hold_action
? computeActionTooltip(stateName, config.hold_action, true)
? computeActionTooltip(hass, stateName, config.hold_action, true)
: "";

const newline = tapTooltip && holdTooltip ? "\n" : "";
Expand All @@ -40,6 +44,7 @@ export const computeTooltip = (hass: HomeAssistant, config: Config): string => {
};

function computeActionTooltip(
hass: HomeAssistant,
state: string,
config: ActionConfig,
isHold: boolean
Expand All @@ -48,20 +53,39 @@ function computeActionTooltip(
return "";
}

let tooltip = isHold ? "Hold: " : "Tap: ";
let tooltip =
(isHold
? hass.localize("ui.panel.lovelace.cards.picture-elements.hold")
: hass.localize("ui.panel.lovelace.cards.picture-elements.tap")) + " ";

switch (config.action) {
case "navigate":
tooltip += `Navigate to ${config.navigation_path}`;
tooltip += `${hass.localize(
"ui.panel.lovelace.cards.picture-elements.navigate_to",
"location",
config.navigation_path
)}`;
break;
case "toggle":
tooltip += `Toggle ${state}`;
tooltip += `${hass.localize(
"ui.panel.lovelace.cards.picture-elements.toggle",
"name",
state
)}`;
break;
case "call-service":
tooltip += `Call service ${config.service}`;
tooltip += `${hass.localize(
"ui.panel.lovelace.cards.picture-elements.call_service",
"name",
config.service
)}`;
break;
case "more-info":
tooltip += `Show more-info: ${state}`;
tooltip += `${hass.localize(
"ui.panel.lovelace.cards.picture-elements.more_info",
"name",
state
)}`;
break;
}

Expand Down
8 changes: 8 additions & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,14 @@
"checked_items": "Checked items",
"clear_items": "Clear checked items",
"add_item": "Add item"
},
"picture-elements": {
"hold": "Hold:",
"tap": "Tap:",
"navigate_to": "Navigate to {location}",
"toggle": "Toggle {name}",
"call_service": "Call service {name}",
"more_info": "Show more-info: {name}"
}
},
"menu": {
Expand Down