Revert "feat(action): Support for `press_action` and `release_action`"
This reverts commit 27043d7c11
.
This commit is contained in:
parent
27043d7c11
commit
452ee0ff24
|
@ -1961,12 +1961,6 @@ views:
|
||||||
var now = new Date();
|
var now = new Date();
|
||||||
return `${now} <br/>- ${last_changed}`
|
return `${now} <br/>- ${last_changed}`
|
||||||
]]]
|
]]]
|
||||||
tap_action:
|
|
||||||
action: none
|
|
||||||
press_action:
|
|
||||||
action: toggle
|
|
||||||
release_action:
|
|
||||||
action: toggle
|
|
||||||
- type: custom:button-card
|
- type: custom:button-card
|
||||||
entity: input_number.test
|
entity: input_number.test
|
||||||
show_state: true
|
show_state: true
|
||||||
|
|
|
@ -60,7 +60,7 @@ Lovelace Button card for your entities.
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- works with any toggleable entity
|
- 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)
|
- state display (optional)
|
||||||
- custom color (optional), or based on light rgb value/temperature
|
- custom color (optional), or based on light rgb value/temperature
|
||||||
- custom state definition with customizable color, icon and style (optional)
|
- 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. |
|
| `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. |
|
| `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. |
|
| `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) |
|
| `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) |
|
| `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) |
|
| `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) |
|
||||||
|
|
|
@ -16,7 +16,7 @@ interface ActionHandler extends HTMLElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ActionHandlerDetail {
|
export interface ActionHandlerDetail {
|
||||||
action: 'hold' | 'tap' | 'double_tap' | 'press' | 'release';
|
action: 'hold' | 'tap' | 'double_tap';
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ActionHandlerOptions {
|
export interface ActionHandlerOptions {
|
||||||
|
@ -138,7 +138,6 @@ class ActionHandler extends HTMLElement implements ActionHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
element.actionHandler.start = (ev: Event) => {
|
element.actionHandler.start = (ev: Event) => {
|
||||||
fireEvent(element, 'action', { action: 'press' });
|
|
||||||
this.cancelled = false;
|
this.cancelled = false;
|
||||||
let x;
|
let x;
|
||||||
let y;
|
let y;
|
||||||
|
@ -185,7 +184,6 @@ class ActionHandler extends HTMLElement implements ActionHandler {
|
||||||
if (ev.cancelable) {
|
if (ev.cancelable) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
}
|
}
|
||||||
fireEvent(element, 'action', { action: 'release' });
|
|
||||||
if (options.hasHold) {
|
if (options.hasHold) {
|
||||||
clearTimeout(this.timer);
|
clearTimeout(this.timer);
|
||||||
if (this.isRepeating && this.repeatTimeout) {
|
if (this.isRepeating && this.repeatTimeout) {
|
||||||
|
|
|
@ -701,9 +701,6 @@ class ButtonCard extends LitElement {
|
||||||
const tap_action = this._getTemplateOrValue(state, this._config!.tap_action!.action);
|
const tap_action = this._getTemplateOrValue(state, this._config!.tap_action!.action);
|
||||||
const hold_action = this._getTemplateOrValue(state, this._config!.hold_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 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;
|
let hasChildCards = false;
|
||||||
if (this._config!.custom_fields) {
|
if (this._config!.custom_fields) {
|
||||||
hasChildCards = Object.keys(this._config!.custom_fields).some((key) => {
|
hasChildCards = Object.keys(this._config!.custom_fields).some((key) => {
|
||||||
|
@ -725,14 +722,7 @@ class ButtonCard extends LitElement {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (
|
if (tap_action != 'none' || hold_action != 'none' || double_tap_action != 'none' || hasChildCards) {
|
||||||
tap_action != 'none' ||
|
|
||||||
hold_action != 'none' ||
|
|
||||||
double_tap_action != 'none' ||
|
|
||||||
press_action != 'none' ||
|
|
||||||
release_action != 'none' ||
|
|
||||||
hasChildCards
|
|
||||||
) {
|
|
||||||
clickable = true;
|
clickable = true;
|
||||||
} else {
|
} else {
|
||||||
clickable = false;
|
clickable = false;
|
||||||
|
@ -1065,8 +1055,6 @@ class ButtonCard extends LitElement {
|
||||||
group_expand: false,
|
group_expand: false,
|
||||||
hold_action: { action: 'none' },
|
hold_action: { action: 'none' },
|
||||||
double_tap_action: { action: 'none' },
|
double_tap_action: { action: 'none' },
|
||||||
press_action: { action: 'none' },
|
|
||||||
release_action: { action: 'none' },
|
|
||||||
layout: 'vertical',
|
layout: 'vertical',
|
||||||
size: '40%',
|
size: '40%',
|
||||||
color_type: 'icon',
|
color_type: 'icon',
|
||||||
|
@ -1224,21 +1212,10 @@ class ButtonCard extends LitElement {
|
||||||
case 'tap':
|
case 'tap':
|
||||||
case 'hold':
|
case 'hold':
|
||||||
case 'double_tap':
|
case 'double_tap':
|
||||||
case 'press':
|
|
||||||
case 'release':
|
|
||||||
const config = this._config;
|
const config = this._config;
|
||||||
if (!config) return;
|
if (!config) return;
|
||||||
const action = ev.detail.action;
|
const action = ev.detail.action;
|
||||||
const localAction = this._evalActions(config, `${action}_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);
|
handleAction(this, this._hass!, localAction, action);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -18,8 +18,6 @@ export interface ButtonCardConfig {
|
||||||
tap_action?: ActionConfig;
|
tap_action?: ActionConfig;
|
||||||
hold_action?: ActionConfig;
|
hold_action?: ActionConfig;
|
||||||
double_tap_action?: ActionConfig;
|
double_tap_action?: ActionConfig;
|
||||||
press_action?: ActionConfig;
|
|
||||||
release_action?: ActionConfig;
|
|
||||||
show_name?: boolean;
|
show_name?: boolean;
|
||||||
show_state?: boolean;
|
show_state?: boolean;
|
||||||
show_icon?: boolean;
|
show_icon?: boolean;
|
||||||
|
|
Loading…
Reference in New Issue