Skip to content
Merged
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
23 changes: 19 additions & 4 deletions src/panels/lovelace/common/handle-action.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { fireEvent } from "../../../common/dom/fire_event";
import { navigate } from "../../../common/navigate";
import { forwardHaptic } from "../../../data/haptics";
import { domainToName } from "../../../data/integration";
import { ActionConfig } from "../../../data/lovelace";
import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box";
import { HomeAssistant } from "../../../types";
Expand Down Expand Up @@ -50,17 +51,31 @@ export const handleAction = async (
) {
forwardHaptic("warning");

let serviceName;
if (actionConfig.action === "call-service") {
const [domain, service] = actionConfig.service.split(".", 2);
const serviceDomains = hass.services;
if (domain in serviceDomains && service in serviceDomains[domain]) {
const localize = await hass.loadBackendTranslation("title");
serviceName = `${domainToName(localize, domain)}: ${
serviceDomains[domain][service].name || service
}`;
}
}

if (
!(await showConfirmationDialog(node, {
text:
actionConfig.confirmation.text ||
hass.localize(
"ui.panel.lovelace.cards.actions.action_confirmation",
"action",
hass.localize(
"ui.panel.lovelace.editor.action-editor.actions." +
actionConfig.action
) || actionConfig.action
serviceName ||
hass.localize(
"ui.panel.lovelace.editor.action-editor.actions." +
actionConfig.action
) ||
Comment on lines +74 to +77
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still want to show this part I think, just add what service will be called?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I think many names assume that they will be used together with the domain/integration name, and not stand alone?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the end-user does not care if it is technically a "service" or not that is being called. So I opted only for the name.

I agree reg. the domain part. Need to see how to best include that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bramkragten I attempted to take over the logic that is also used in the ha-service-picker for the domain. The problem is that I cannot get the translations to get loaded. So the first time the popup gets shown, the domain is not translated, the second time around it is.

I attempted to manually force the "title" loading via hass.loadBackendTranslation("title"); but I did not have any effect.

=> Any hints / tips?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a timing issue then? Do you await it? And use its result as input for domainToName?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sure I did, but apparently both individually (either await or local var) and not combined (await + local var). Tried that now, and seems to work:

image

Comment thread
spacegaier marked this conversation as resolved.
actionConfig.action
),
}))
) {
Expand Down