Add error handling to action handling (#8187)

This commit is contained in:
Philip Allgaier 2021-01-21 19:38:19 +01:00 committed by GitHub
parent 136ebb5a07
commit 9e99d158fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 6 deletions

View File

@ -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;
}

View File

@ -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": {