From 9e99d158fd45753d4bd0ae50ac3831958117211a Mon Sep 17 00:00:00 2001 From: Philip Allgaier Date: Thu, 21 Jan 2021 19:38:19 +0100 Subject: [PATCH] Add error handling to action handling (#8187) --- src/panels/lovelace/common/handle-action.ts | 37 +++++++++++++++++++-- src/translations/en.json | 15 ++++++--- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/panels/lovelace/common/handle-action.ts b/src/panels/lovelace/common/handle-action.ts index 053056c325..ad95273e5d 100644 --- a/src/panels/lovelace/common/handle-action.ts +++ b/src/panels/lovelace/common/handle-action.ts @@ -4,6 +4,7 @@ import { forwardHaptic } from "../../../data/haptics"; import { ActionConfig } from "../../../data/lovelace"; import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box"; import { HomeAssistant } from "../../../types"; +import { showToast } from "../../../util/toast"; import { toggleEntity } from "./entity/toggle-entity"; declare global { @@ -54,9 +55,12 @@ export const handleAction = async ( text: actionConfig.confirmation.text || hass.localize( - "ui.panel.lovelace.cards.action_confirmation", + "ui.panel.lovelace.cards.actions.action_confirmation", "action", - actionConfig.action + hass.localize( + "ui.panel.lovelace.editor.action-editor.actions." + + actionConfig.action + ) || actionConfig.action ), })) ) { @@ -70,17 +74,36 @@ export const handleAction = async ( fireEvent(node, "hass-more-info", { entityId: config.entity ? config.entity : config.camera_image!, }); + } else { + showToast(node, { + message: hass.localize( + "ui.panel.lovelace.cards.actions.no_entity_more_info" + ), + }); + forwardHaptic("failure"); } break; } case "navigate": if (actionConfig.navigation_path) { navigate(node, actionConfig.navigation_path); + } else { + showToast(node, { + message: hass.localize( + "ui.panel.lovelace.cards.actions.no_navigation_path" + ), + }); + forwardHaptic("failure"); } break; case "url": { if (actionConfig.url_path) { window.open(actionConfig.url_path); + } else { + showToast(node, { + message: hass.localize("ui.panel.lovelace.cards.actions.no_url"), + }); + forwardHaptic("failure"); } break; } @@ -88,11 +111,21 @@ export const handleAction = async ( if (config.entity) { toggleEntity(hass, config.entity!); forwardHaptic("light"); + } else { + showToast(node, { + message: hass.localize( + "ui.panel.lovelace.cards.actions.no_entity_toggle" + ), + }); + forwardHaptic("failure"); } break; } case "call-service": { if (!actionConfig.service) { + showToast(node, { + message: hass.localize("ui.panel.lovelace.cards.actions.no_service"), + }); forwardHaptic("failure"); return; } diff --git a/src/translations/en.json b/src/translations/en.json index 76bb2d2062..8352f1a64b 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -2435,7 +2435,14 @@ "lovelace": { "cards": { "confirm_delete": "Are you sure you want to delete this card?", - "action_confirmation": "Are you sure you want to exectue action \"{action}\"?", + "actions": { + "action_confirmation": "Are you sure you want to exectue action \"{action}\"?", + "no_entity_more_info": "No entity provided for more info dialog", + "no_entity_toggle": "No entity provided to toggle", + "no_navigation_path": "No navigation path specified", + "no_url": "No URL to open specified", + "no_service": "No service for execution specified" + }, "empty_state": { "title": "Welcome Home", "no_devices": "This page allows you to control your devices, however it looks like you have no devices set up yet. Head to the integrations page to get started.", @@ -2458,7 +2465,7 @@ "url": "Open window to {url_path}", "toggle": "Toggle {name}", "call_service": "Call service {name}", - "more_info": "Show more-info: {name}" + "more_info": "Show more info: {name}" }, "safe-mode": { "header": "Safe Mode Activated", @@ -2687,7 +2694,7 @@ "button": { "name": "Button", "description": "The Button card allows you to add buttons to perform tasks.", - "default_action_help": "The default action depends on the entity's capabilities, it will either be toggled or the more info will be shown." + "default_action_help": "The default action depends on the entity's capabilities, it will either be toggled or the more info dialog will be shown." }, "entity-filter": { "name": "Entity Filter", @@ -2803,7 +2810,7 @@ }, "picture-glance": { "name": "Picture Glance", - "description": "The Picture Glance card shows an image and corresponding entity states as an icon. The entities on the right side allow toggle actions, others show the more information dialog.", + "description": "The Picture Glance card shows an image and corresponding entity states as an icon. The entities on the right side allow toggle actions, others show the more info dialog.", "state_entity": "State Entity" }, "plant-status": {