Skip to content

Commit

Permalink
change actionType to match key names
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerwyn committed Dec 10, 2023
1 parent 0c4c6fe commit e4b4276
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 32 deletions.
12 changes: 6 additions & 6 deletions dist/android-tv-card.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/android-tv-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import {
IConfig,
IActions,
IAction,
IData,
Action,
TouchAction,
defaultKeys,
defaultSources,
IData,
} from './models';

import './classes/remote-button';
Expand Down
4 changes: 2 additions & 2 deletions src/classes/base-remote-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class BaseRemoteElement extends LitElement {
entity_id: renderTemplate(this.hass, this.remoteId as string),
command: renderTemplate(this.hass, key),
};
if (actionType == 'hold') {
if (actionType == 'hold_action') {
data.hold_secs = 0.5;
}
this.hass.callService('remote', 'send_command', data);
Expand All @@ -83,7 +83,7 @@ export class BaseRemoteElement extends LitElement {
for (const key in data) {
data[key] = renderTemplate(this.hass, data[key] as string);
}
if (actionType == 'hold' && domainService == 'remote.send_command') {
if (actionType == 'hold_action' && domainService == 'remote.send_command') {
data.hold_secs = 0.5;
}

Expand Down
22 changes: 11 additions & 11 deletions src/classes/remote-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export class RemoteButton extends BaseRemoteElement {
this.clickTimer = undefined;

const actionToHaptic: Record<ActionType, HapticType> = {
single: 'light',
hold: 'medium',
double: 'success',
tap_action: 'light',
hold_action: 'medium',
double_tap_action: 'success',
};
let haptic = actionToHaptic[actionType];
if (['up', 'down', 'left', 'right'].includes(this.actionKey)) {
Expand All @@ -36,13 +36,13 @@ export class RemoteButton extends BaseRemoteElement {

let action;
switch (actionType) {
case 'hold':
case 'hold_action':
action = this.actions.hold_action!;
break;
case 'double':
case 'double_tap_action':
action = this.actions.double_tap_action!;
break;
case 'single':
case 'tap_action':
default:
action = this.actions.tap_action!;
break;
Expand All @@ -60,14 +60,14 @@ export class RemoteButton extends BaseRemoteElement {

if ('double_tap_action' in this.actions) {
if (this.clickCount == 2) {
this.clickAction('double');
this.clickAction('double_tap_action');
} else {
this.clickTimer = setTimeout(() => {
this.clickAction('single');
this.clickAction('tap_action');
}, 200);
}
} else {
this.clickAction('single');
this.clickAction('hold_action');
}
}

Expand All @@ -79,10 +79,10 @@ export class RemoteButton extends BaseRemoteElement {
// prettier-ignore
if (['up', 'down', 'left', 'right', 'volume_up', 'volume_down', 'delete'].includes(this.actionKey)) {
this.holdInterval = setInterval(() => {
this.clickAction('single')
this.clickAction('tap_action')
}, 100);
} else {
this.clickAction('hold')
this.clickAction('hold_action')
}
}, 500);
}
Expand Down
2 changes: 1 addition & 1 deletion src/classes/remote-keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class RemoteKeyboard extends BaseKeyboardElement {
case 'ANDROID_TV':
case 'ANDROID TV':
default:
this.sendCommand(key, 'single');
this.sendCommand(key, 'tap_action');
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/classes/remote-slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class RemoteSlider extends BaseRemoteElement {
}

this.fireHapticEvent('light');
this.callService(this.actions.tap_action!.service!, data, 'single');
this.callService(this.actions.tap_action!.service!, data, 'tap_action');

this.value = this.newValue;
}
Expand Down
10 changes: 5 additions & 5 deletions src/classes/remote-touchpad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class RemoteTouchpad extends BaseRemoteElement {
clearTimeout(this.clickTimer as ReturnType<typeof setTimeout>);
this.clickTimer = undefined;
this.fireHapticEvent('light');
this.sendAction(this.touchActions['center'], 'single');
this.sendAction(this.touchActions['center'], 'tap_action');
this.clickCount = 0;
};
if (e.detail && e.detail > this.clickCount) {
Expand Down Expand Up @@ -70,7 +70,7 @@ export class RemoteTouchpad extends BaseRemoteElement {
this.clickCount = 0;

this.fireHapticEvent('success');
this.sendAction(this.touchActions.double, 'double');
this.sendAction(this.touchActions.double, 'double_tap_action');
}

@eventOptions({ passive: true })
Expand All @@ -90,12 +90,12 @@ export class RemoteTouchpad extends BaseRemoteElement {
this.fireHapticEvent('selection');
this.sendAction(
this.touchActions[this.touchAction as TouchAction],
'single',
'tap_action',
);
}, 100);
} else {
this.fireHapticEvent('medium');
this.sendAction(this.touchActions.hold, 'hold');
this.sendAction(this.touchActions.hold, 'hold_action');
}
}, 500);

Expand Down Expand Up @@ -143,7 +143,7 @@ export class RemoteTouchpad extends BaseRemoteElement {
}
this.fireHapticEvent('selection');
this.touchAction = action as TouchAction;
this.sendAction(this.touchActions[action as TouchAction], 'single');
this.sendAction(this.touchActions[action as TouchAction], 'tap_action');

window.initialX = undefined;
window.initialY = undefined;
Expand Down
3 changes: 1 addition & 2 deletions src/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './enums';
export * from './interfaces';
export * from './defaultKeys';
export * from './defaultSources';
export * from './maps';
2 changes: 1 addition & 1 deletion src/models/interfaces/IActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export interface IActions {
double_tap_action?: IAction;
}

export type ActionType = 'single' | 'hold' | 'double';
export type ActionType = 'tap_action' | 'hold_action' | 'double_tap_action';

export type TouchAction =
| 'up'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IActions } from '.';
import { IActions } from '..';

/**
* This is the list of most common commands from the Android TV Remote integration page.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IActions, svg } from '.';
import { IActions, svg } from '..';

/**
* This is a list of common streaming apps, their icons, and the deep links to open them in Android TV, mostly collected from the following Home Assistant Community Forum guide.
Expand Down
2 changes: 2 additions & 0 deletions src/models/maps/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './defaultKeys'
export * from './defaultSources'

0 comments on commit e4b4276

Please sign in to comment.