mirror of
https://github.com/home-assistant/frontend.git
synced 2025-08-01 13:37:47 +00:00
Allow multiple tap/hold/doubletap actions.
This commit is contained in:
parent
1538fbb102
commit
4dcfe3031d
@ -148,6 +148,11 @@ export interface CustomActionConfig extends BaseActionConfig {
|
|||||||
action: "fire-dom-event";
|
action: "fire-dom-event";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface MultipleActionConfig extends BaseActionConfig {
|
||||||
|
action: "multiple";
|
||||||
|
actions: ActionConfig[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface BaseActionConfig {
|
export interface BaseActionConfig {
|
||||||
confirmation?: ConfirmationRestrictionConfig;
|
confirmation?: ConfirmationRestrictionConfig;
|
||||||
}
|
}
|
||||||
@ -168,7 +173,8 @@ export type ActionConfig =
|
|||||||
| UrlActionConfig
|
| UrlActionConfig
|
||||||
| MoreInfoActionConfig
|
| MoreInfoActionConfig
|
||||||
| NoActionConfig
|
| NoActionConfig
|
||||||
| CustomActionConfig;
|
| CustomActionConfig
|
||||||
|
| MultipleActionConfig;
|
||||||
|
|
||||||
type LovelaceUpdatedEvent = HassEventBase & {
|
type LovelaceUpdatedEvent = HassEventBase & {
|
||||||
event_type: "lovelace_updated";
|
event_type: "lovelace_updated";
|
||||||
|
@ -40,69 +40,74 @@ export const handleAction = async (
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
const actionConfigs =
|
||||||
actionConfig.confirmation &&
|
actionConfig.action === "multiple" ? actionConfig.actions : [actionConfig];
|
||||||
(!actionConfig.confirmation.exemptions ||
|
|
||||||
!actionConfig.confirmation.exemptions.some(
|
|
||||||
(e) => e.user === hass!.user!.id
|
|
||||||
))
|
|
||||||
) {
|
|
||||||
forwardHaptic("warning");
|
|
||||||
|
|
||||||
|
for await (actionConfig of actionConfigs) {
|
||||||
if (
|
if (
|
||||||
!(await showConfirmationDialog(node, {
|
actionConfig.confirmation &&
|
||||||
text:
|
(!actionConfig.confirmation.exemptions ||
|
||||||
actionConfig.confirmation.text ||
|
!actionConfig.confirmation.exemptions.some(
|
||||||
hass.localize(
|
(e) => e.user === hass!.user!.id
|
||||||
"ui.panel.lovelace.cards.action_confirmation",
|
))
|
||||||
"action",
|
|
||||||
actionConfig.action
|
|
||||||
),
|
|
||||||
}))
|
|
||||||
) {
|
) {
|
||||||
return;
|
forwardHaptic("warning");
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (actionConfig.action) {
|
if (
|
||||||
case "more-info": {
|
!(await showConfirmationDialog(node, {
|
||||||
if (config.entity || config.camera_image) {
|
text:
|
||||||
fireEvent(node, "hass-more-info", {
|
actionConfig.confirmation.text ||
|
||||||
entityId: config.entity ? config.entity : config.camera_image!,
|
hass.localize(
|
||||||
});
|
"ui.panel.lovelace.cards.action_confirmation",
|
||||||
}
|
"action",
|
||||||
break;
|
actionConfig.action
|
||||||
}
|
),
|
||||||
case "navigate":
|
}))
|
||||||
if (actionConfig.navigation_path) {
|
) {
|
||||||
navigate(node, actionConfig.navigation_path);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "url": {
|
|
||||||
if (actionConfig.url_path) {
|
|
||||||
window.open(actionConfig.url_path);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "toggle": {
|
|
||||||
if (config.entity) {
|
|
||||||
toggleEntity(hass, config.entity!);
|
|
||||||
forwardHaptic("light");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "call-service": {
|
|
||||||
if (!actionConfig.service) {
|
|
||||||
forwardHaptic("failure");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const [domain, service] = actionConfig.service.split(".", 2);
|
|
||||||
hass.callService(domain, service, actionConfig.service_data);
|
|
||||||
forwardHaptic("light");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case "fire-dom-event": {
|
|
||||||
fireEvent(node, "ll-custom", actionConfig);
|
switch (actionConfig.action) {
|
||||||
|
case "more-info": {
|
||||||
|
if (config.entity || config.camera_image) {
|
||||||
|
fireEvent(node, "hass-more-info", {
|
||||||
|
entityId: config.entity ? config.entity : config.camera_image!,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "navigate":
|
||||||
|
if (actionConfig.navigation_path) {
|
||||||
|
navigate(node, actionConfig.navigation_path);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "url": {
|
||||||
|
if (actionConfig.url_path) {
|
||||||
|
window.open(actionConfig.url_path);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "toggle": {
|
||||||
|
if (config.entity) {
|
||||||
|
toggleEntity(hass, config.entity!);
|
||||||
|
forwardHaptic("light");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "call-service": {
|
||||||
|
if (!actionConfig.service) {
|
||||||
|
forwardHaptic("failure");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const [domain, service] = actionConfig.service.split(".", 2);
|
||||||
|
hass.callService(domain, service, actionConfig.service_data);
|
||||||
|
forwardHaptic("light");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "fire-dom-event": {
|
||||||
|
fireEvent(node, "ll-custom", actionConfig);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -130,6 +130,15 @@ export class HuiActionEditor extends LitElement {
|
|||||||
</b>
|
</b>
|
||||||
`
|
`
|
||||||
: ""}
|
: ""}
|
||||||
|
${this.config?.action === "multiple"
|
||||||
|
? html`
|
||||||
|
<b>
|
||||||
|
${this.hass!.localize(
|
||||||
|
"ui.panel.lovelace.editor.action-editor.editor_multiple_actions"
|
||||||
|
)}
|
||||||
|
</b>
|
||||||
|
`
|
||||||
|
: ""}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@ const actions = [
|
|||||||
"url",
|
"url",
|
||||||
"call-service",
|
"call-service",
|
||||||
"none",
|
"none",
|
||||||
|
"multiple",
|
||||||
];
|
];
|
||||||
|
|
||||||
@customElement("hui-button-card-editor")
|
@customElement("hui-button-card-editor")
|
||||||
|
@ -82,6 +82,7 @@ export class HuiLightCardEditor extends LitElement
|
|||||||
"url",
|
"url",
|
||||||
"call-service",
|
"call-service",
|
||||||
"none",
|
"none",
|
||||||
|
"multiple",
|
||||||
];
|
];
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
|
@ -60,7 +60,7 @@ export class HuiPictureCardEditor extends LitElement
|
|||||||
return html``;
|
return html``;
|
||||||
}
|
}
|
||||||
|
|
||||||
const actions = ["navigate", "url", "call-service", "none"];
|
const actions = ["navigate", "url", "call-service", "none", "multiple"];
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<div class="card-config">
|
<div class="card-config">
|
||||||
|
@ -104,7 +104,14 @@ export class HuiPictureEntityCardEditor extends LitElement
|
|||||||
return html``;
|
return html``;
|
||||||
}
|
}
|
||||||
|
|
||||||
const actions = ["more-info", "toggle", "navigate", "call-service", "none"];
|
const actions = [
|
||||||
|
"more-info",
|
||||||
|
"toggle",
|
||||||
|
"navigate",
|
||||||
|
"call-service",
|
||||||
|
"none",
|
||||||
|
"multiple",
|
||||||
|
];
|
||||||
const views = ["auto", "live"];
|
const views = ["auto", "live"];
|
||||||
const dir = computeRTLDirection(this.hass!);
|
const dir = computeRTLDirection(this.hass!);
|
||||||
|
|
||||||
|
@ -108,7 +108,14 @@ export class HuiPictureGlanceCardEditor extends LitElement
|
|||||||
return html``;
|
return html``;
|
||||||
}
|
}
|
||||||
|
|
||||||
const actions = ["more-info", "toggle", "navigate", "call-service", "none"];
|
const actions = [
|
||||||
|
"more-info",
|
||||||
|
"toggle",
|
||||||
|
"navigate",
|
||||||
|
"call-service",
|
||||||
|
"none",
|
||||||
|
"multiple",
|
||||||
|
];
|
||||||
const views = ["auto", "live"];
|
const views = ["auto", "live"];
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
|
@ -98,6 +98,7 @@ export const actionConfigStruct = object({
|
|||||||
url_path: optional(string()),
|
url_path: optional(string()),
|
||||||
service: optional(string()),
|
service: optional(string()),
|
||||||
service_data: optional(object()),
|
service_data: optional(object()),
|
||||||
|
actions: optional(array()),
|
||||||
});
|
});
|
||||||
|
|
||||||
const buttonEntitiesRowConfigStruct = object({
|
const buttonEntitiesRowConfigStruct = object({
|
||||||
|
@ -2564,6 +2564,7 @@
|
|||||||
"action-editor": {
|
"action-editor": {
|
||||||
"navigation_path": "Navigation Path",
|
"navigation_path": "Navigation Path",
|
||||||
"url_path": "URL Path",
|
"url_path": "URL Path",
|
||||||
|
"editor_multiple_actions": "Multiple actions can only be entered in the code editor",
|
||||||
"editor_service_data": "Service data can only be entered in the code editor",
|
"editor_service_data": "Service data can only be entered in the code editor",
|
||||||
"actions": {
|
"actions": {
|
||||||
"default_action": "Default Action",
|
"default_action": "Default Action",
|
||||||
@ -2572,7 +2573,8 @@
|
|||||||
"toggle": "Toggle",
|
"toggle": "Toggle",
|
||||||
"navigate": "Navigate",
|
"navigate": "Navigate",
|
||||||
"url": "URL",
|
"url": "URL",
|
||||||
"none": "No Action"
|
"none": "No Action",
|
||||||
|
"multiple": "Multiple actions"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"card": {
|
"card": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user