Revert "feat(action): Support for `press_action` and `release_action`"

This reverts commit 27043d7c11.
This commit is contained in:
Jérôme Wiedemann 2023-07-24 18:50:15 +00:00
parent 27043d7c11
commit 452ee0ff24
5 changed files with 3 additions and 38 deletions

View File

@ -1961,12 +1961,6 @@ views:
var now = new Date();
return `${now} <br/>- ${last_changed}`
]]]
tap_action:
action: none
press_action:
action: toggle
release_action:
action: toggle
- type: custom:button-card
entity: input_number.test
show_state: true

View File

@ -60,7 +60,7 @@ Lovelace Button card for your entities.
## Features
- works with any toggleable entity
- 7 available actions on **tap**, **hold**, **double click**, **press** or **release** : `none`, `toggle`, `more-info`, `navigate`, `url`, `assist` and `call-service`
- 6 available actions on **tap** and/or **hold** and/or **double click**: `none`, `toggle`, `more-info`, `navigate`, `url` and `call-service`
- state display (optional)
- custom color (optional), or based on light rgb value/temperature
- custom state definition with customizable color, icon and style (optional)
@ -101,8 +101,6 @@ Lovelace Button card for your entities.
| `tap_action` | object | optional | See [Action](#Action) | Define the type of action on click, if undefined, toggle will be used. |
| `hold_action` | object | optional | See [Action](#Action) | Define the type of action on hold, if undefined, nothing happens. |
| `double_tap_action` | object | optional | See [Action](#Action) | Define the type of action on double click, if undefined, nothing happens. |
| `press_action` | object | optional | See [Action](#Action) | Define the type of action on press (triggers the moment your click the button), if undefined, nothing happens. You shouldn't mix it with `tap_action` |
| `release_action` | object | optional | See [Action](#Action) | Define the type of action on release (triggers the moment your release the button), if undefined, nothing happens. You shouldn't mix it with `tap_action` |
| `name` | string | optional | `Air conditioner` | Define an optional text to show below the icon. Supports templates, see [templates](#javascript-templates) |
| `state_display` | string | optional | `On` | Override the way the state is displayed. Supports templates, see [templates](#javascript-templates) |
| `label` | string | optional | Any string that you want | Display a label below the card. See [Layouts](#layout) for more information. Supports templates, see [templates](#javascript-templates) |

View File

@ -16,7 +16,7 @@ interface ActionHandler extends HTMLElement {
}
export interface ActionHandlerDetail {
action: 'hold' | 'tap' | 'double_tap' | 'press' | 'release';
action: 'hold' | 'tap' | 'double_tap';
}
export interface ActionHandlerOptions {
@ -138,7 +138,6 @@ class ActionHandler extends HTMLElement implements ActionHandler {
}
element.actionHandler.start = (ev: Event) => {
fireEvent(element, 'action', { action: 'press' });
this.cancelled = false;
let x;
let y;
@ -185,7 +184,6 @@ class ActionHandler extends HTMLElement implements ActionHandler {
if (ev.cancelable) {
ev.preventDefault();
}
fireEvent(element, 'action', { action: 'release' });
if (options.hasHold) {
clearTimeout(this.timer);
if (this.isRepeating && this.repeatTimeout) {

View File

@ -701,9 +701,6 @@ class ButtonCard extends LitElement {
const tap_action = this._getTemplateOrValue(state, this._config!.tap_action!.action);
const hold_action = this._getTemplateOrValue(state, this._config!.hold_action!.action);
const double_tap_action = this._getTemplateOrValue(state, this._config!.double_tap_action!.action);
const press_action = this._getTemplateOrValue(state, this._config!.press_action!.action);
const release_action = this._getTemplateOrValue(state, this._config!.release_action!.action);
let hasChildCards = false;
if (this._config!.custom_fields) {
hasChildCards = Object.keys(this._config!.custom_fields).some((key) => {
@ -725,14 +722,7 @@ class ButtonCard extends LitElement {
}));
}
}
if (
tap_action != 'none' ||
hold_action != 'none' ||
double_tap_action != 'none' ||
press_action != 'none' ||
release_action != 'none' ||
hasChildCards
) {
if (tap_action != 'none' || hold_action != 'none' || double_tap_action != 'none' || hasChildCards) {
clickable = true;
} else {
clickable = false;
@ -1065,8 +1055,6 @@ class ButtonCard extends LitElement {
group_expand: false,
hold_action: { action: 'none' },
double_tap_action: { action: 'none' },
press_action: { action: 'none' },
release_action: { action: 'none' },
layout: 'vertical',
size: '40%',
color_type: 'icon',
@ -1224,21 +1212,10 @@ class ButtonCard extends LitElement {
case 'tap':
case 'hold':
case 'double_tap':
case 'press':
case 'release':
const config = this._config;
if (!config) return;
const action = ev.detail.action;
const localAction = this._evalActions(config, `${action}_action`);
if (!localAction || !localAction[`${action}_action`] || localAction[`${action}_action`].action === 'none') {
break;
}
if (action === 'press' || action === 'release') {
// Hack HA (because it only supports tap, hold and dble_tap with the hass-action event)
localAction.tap_action = localAction[`${action}_action`];
handleAction(this, this._hass!, localAction, 'tap');
break;
}
handleAction(this, this._hass!, localAction, action);
break;
default:

View File

@ -18,8 +18,6 @@ export interface ButtonCardConfig {
tap_action?: ActionConfig;
hold_action?: ActionConfig;
double_tap_action?: ActionConfig;
press_action?: ActionConfig;
release_action?: ActionConfig;
show_name?: boolean;
show_state?: boolean;
show_icon?: boolean;