From 452ee0ff24742886bf5b18fbd881adbeb2177c0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Wiedemann?= Date: Mon, 24 Jul 2023 18:50:15 +0000 Subject: [PATCH] Revert "feat(action): Support for `press_action` and `release_action`" This reverts commit 27043d7c114a2757206f852a7e9184f94101c153. --- .devcontainer/ui-lovelace.yaml | 6 ------ README.md | 4 +--- src/action-handler.ts | 4 +--- src/button-card.ts | 25 +------------------------ src/types/types.ts | 2 -- 5 files changed, 3 insertions(+), 38 deletions(-) diff --git a/.devcontainer/ui-lovelace.yaml b/.devcontainer/ui-lovelace.yaml index 159a904..6987567 100644 --- a/.devcontainer/ui-lovelace.yaml +++ b/.devcontainer/ui-lovelace.yaml @@ -1961,12 +1961,6 @@ views: var now = new Date(); return `${now}
- ${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 diff --git a/README.md b/README.md index fcba79a..47f2eca 100644 --- a/README.md +++ b/README.md @@ -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) | diff --git a/src/action-handler.ts b/src/action-handler.ts index 52c4eae..87066ae 100644 --- a/src/action-handler.ts +++ b/src/action-handler.ts @@ -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) { diff --git a/src/button-card.ts b/src/button-card.ts index bc2b99b..4bfb1f6 100644 --- a/src/button-card.ts +++ b/src/button-card.ts @@ -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: diff --git a/src/types/types.ts b/src/types/types.ts index b1ae158..1058148 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -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;