mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 09:16:38 +00:00
Add error handling to action handling (#8187)
This commit is contained in:
parent
136ebb5a07
commit
9e99d158fd
@ -4,6 +4,7 @@ import { forwardHaptic } from "../../../data/haptics";
|
|||||||
import { ActionConfig } from "../../../data/lovelace";
|
import { ActionConfig } from "../../../data/lovelace";
|
||||||
import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box";
|
import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box";
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
|
import { showToast } from "../../../util/toast";
|
||||||
import { toggleEntity } from "./entity/toggle-entity";
|
import { toggleEntity } from "./entity/toggle-entity";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
@ -54,9 +55,12 @@ export const handleAction = async (
|
|||||||
text:
|
text:
|
||||||
actionConfig.confirmation.text ||
|
actionConfig.confirmation.text ||
|
||||||
hass.localize(
|
hass.localize(
|
||||||
"ui.panel.lovelace.cards.action_confirmation",
|
"ui.panel.lovelace.cards.actions.action_confirmation",
|
||||||
"action",
|
"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", {
|
fireEvent(node, "hass-more-info", {
|
||||||
entityId: config.entity ? config.entity : config.camera_image!,
|
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;
|
break;
|
||||||
}
|
}
|
||||||
case "navigate":
|
case "navigate":
|
||||||
if (actionConfig.navigation_path) {
|
if (actionConfig.navigation_path) {
|
||||||
navigate(node, 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;
|
break;
|
||||||
case "url": {
|
case "url": {
|
||||||
if (actionConfig.url_path) {
|
if (actionConfig.url_path) {
|
||||||
window.open(actionConfig.url_path);
|
window.open(actionConfig.url_path);
|
||||||
|
} else {
|
||||||
|
showToast(node, {
|
||||||
|
message: hass.localize("ui.panel.lovelace.cards.actions.no_url"),
|
||||||
|
});
|
||||||
|
forwardHaptic("failure");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -88,11 +111,21 @@ export const handleAction = async (
|
|||||||
if (config.entity) {
|
if (config.entity) {
|
||||||
toggleEntity(hass, config.entity!);
|
toggleEntity(hass, config.entity!);
|
||||||
forwardHaptic("light");
|
forwardHaptic("light");
|
||||||
|
} else {
|
||||||
|
showToast(node, {
|
||||||
|
message: hass.localize(
|
||||||
|
"ui.panel.lovelace.cards.actions.no_entity_toggle"
|
||||||
|
),
|
||||||
|
});
|
||||||
|
forwardHaptic("failure");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "call-service": {
|
case "call-service": {
|
||||||
if (!actionConfig.service) {
|
if (!actionConfig.service) {
|
||||||
|
showToast(node, {
|
||||||
|
message: hass.localize("ui.panel.lovelace.cards.actions.no_service"),
|
||||||
|
});
|
||||||
forwardHaptic("failure");
|
forwardHaptic("failure");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2435,7 +2435,14 @@
|
|||||||
"lovelace": {
|
"lovelace": {
|
||||||
"cards": {
|
"cards": {
|
||||||
"confirm_delete": "Are you sure you want to delete this card?",
|
"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": {
|
"empty_state": {
|
||||||
"title": "Welcome Home",
|
"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.",
|
"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}",
|
"url": "Open window to {url_path}",
|
||||||
"toggle": "Toggle {name}",
|
"toggle": "Toggle {name}",
|
||||||
"call_service": "Call service {name}",
|
"call_service": "Call service {name}",
|
||||||
"more_info": "Show more-info: {name}"
|
"more_info": "Show more info: {name}"
|
||||||
},
|
},
|
||||||
"safe-mode": {
|
"safe-mode": {
|
||||||
"header": "Safe Mode Activated",
|
"header": "Safe Mode Activated",
|
||||||
@ -2687,7 +2694,7 @@
|
|||||||
"button": {
|
"button": {
|
||||||
"name": "Button",
|
"name": "Button",
|
||||||
"description": "The Button card allows you to add buttons to perform tasks.",
|
"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": {
|
"entity-filter": {
|
||||||
"name": "Entity Filter",
|
"name": "Entity Filter",
|
||||||
@ -2803,7 +2810,7 @@
|
|||||||
},
|
},
|
||||||
"picture-glance": {
|
"picture-glance": {
|
||||||
"name": "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"
|
"state_entity": "State Entity"
|
||||||
},
|
},
|
||||||
"plant-status": {
|
"plant-status": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user