Skip to content

Commit

Permalink
fix: Handle turnOn/turnOff in pressKey() correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbo2002 committed Jan 21, 2022
1 parent c666aa1 commit 7e6eefa
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions src/lib/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export default class NodePyATVDevice implements EventEmitter{
return state.appId;
}

private async _pressKey(key: NodePyATVInternalKeys, executableType = NodePyATVExecutableType.atvscript) {
private async _pressKey(key: NodePyATVInternalKeys, executableType: NodePyATVExecutableType) {
const id = addRequestId();
const parameters = getParamters(this.options);

Expand Down Expand Up @@ -356,127 +356,131 @@ export default class NodePyATVDevice implements EventEmitter{
}

const internalKey = internalKeyEntry[1];
await this._pressKey(internalKey);
const executableType = [NodePyATVKeys.turnOn, NodePyATVKeys.turnOff].includes(key) ?
NodePyATVExecutableType.atvremote :
NodePyATVExecutableType.atvscript;

await this._pressKey(internalKey, executableType);
}

/**
* Send the "down" command
* @category Control
*/
async down(): Promise<void> {
await this._pressKey(NodePyATVInternalKeys.down);
await this._pressKey(NodePyATVInternalKeys.down, NodePyATVExecutableType.atvscript);
}

/**
* Send the "home" command
* @category Control
*/
async home(): Promise<void> {
await this._pressKey(NodePyATVInternalKeys.home);
await this._pressKey(NodePyATVInternalKeys.home, NodePyATVExecutableType.atvscript);
}

/**
* Send the "homeHold" command
* @category Control
*/
async homeHold(): Promise<void> {
await this._pressKey(NodePyATVInternalKeys.homeHold);
await this._pressKey(NodePyATVInternalKeys.homeHold, NodePyATVExecutableType.atvscript);
}

/**
* Send the "left" command
* @category Control
*/
async left(): Promise<void> {
await this._pressKey(NodePyATVInternalKeys.left);
await this._pressKey(NodePyATVInternalKeys.left, NodePyATVExecutableType.atvscript);
}

/**
* Send the "menu" command
* @category Control
*/
async menu(): Promise<void> {
await this._pressKey(NodePyATVInternalKeys.menu);
await this._pressKey(NodePyATVInternalKeys.menu, NodePyATVExecutableType.atvscript);
}

/**
* Send the "next" command
* @category Control
*/
async next(): Promise<void> {
await this._pressKey(NodePyATVInternalKeys.next);
await this._pressKey(NodePyATVInternalKeys.next, NodePyATVExecutableType.atvscript);
}

/**
* Send the "pause" command
* @category Control
*/
async pause(): Promise<void> {
await this._pressKey(NodePyATVInternalKeys.pause);
await this._pressKey(NodePyATVInternalKeys.pause, NodePyATVExecutableType.atvscript);
}

/**
* Send the "play" command
* @category Control
*/
async play(): Promise<void> {
await this._pressKey(NodePyATVInternalKeys.play);
await this._pressKey(NodePyATVInternalKeys.play, NodePyATVExecutableType.atvscript);
}

/**
* Send the "playPause" command
* @category Control
*/
async playPause(): Promise<void> {
await this._pressKey(NodePyATVInternalKeys.playPause);
await this._pressKey(NodePyATVInternalKeys.playPause, NodePyATVExecutableType.atvscript);
}

/**
* Send the "previous" command
* @category Control
*/
async previous(): Promise<void> {
await this._pressKey(NodePyATVInternalKeys.previous);
await this._pressKey(NodePyATVInternalKeys.previous, NodePyATVExecutableType.atvscript);
}

/**
* Send the "right" command
* @category Control
*/
async right(): Promise<void> {
await this._pressKey(NodePyATVInternalKeys.right);
await this._pressKey(NodePyATVInternalKeys.right, NodePyATVExecutableType.atvscript);
}

/**
* Send the "select" command
* @category Control
*/
async select(): Promise<void> {
await this._pressKey(NodePyATVInternalKeys.select);
await this._pressKey(NodePyATVInternalKeys.select, NodePyATVExecutableType.atvscript);
}

/**
* Send the "skipBackward" command
* @category Control
*/
async skipBackward(): Promise<void> {
await this._pressKey(NodePyATVInternalKeys.skipBackward);
await this._pressKey(NodePyATVInternalKeys.skipBackward, NodePyATVExecutableType.atvscript);
}

/**
* Send the "skipForward" command
* @category Control
*/
async skipForward(): Promise<void> {
await this._pressKey(NodePyATVInternalKeys.skipForward);
await this._pressKey(NodePyATVInternalKeys.skipForward, NodePyATVExecutableType.atvscript);
}

/**
* Send the "stop" command
* @category Control
*/
async stop(): Promise<void> {
await this._pressKey(NodePyATVInternalKeys.stop);
await this._pressKey(NodePyATVInternalKeys.stop, NodePyATVExecutableType.atvscript);
}

/**
Expand All @@ -485,39 +489,39 @@ export default class NodePyATVDevice implements EventEmitter{
* @deprecated
*/
async suspend(): Promise<void> {
await this._pressKey(NodePyATVInternalKeys.suspend);
await this._pressKey(NodePyATVInternalKeys.suspend, NodePyATVExecutableType.atvscript);
}

/**
* Send the "topMenu" command
* @category Control
*/
async topMenu(): Promise<void> {
await this._pressKey(NodePyATVInternalKeys.topMenu);
await this._pressKey(NodePyATVInternalKeys.topMenu, NodePyATVExecutableType.atvscript);
}

/**
* Send the "up" command
* @category Control
*/
async up(): Promise<void> {
await this._pressKey(NodePyATVInternalKeys.up);
await this._pressKey(NodePyATVInternalKeys.up, NodePyATVExecutableType.atvscript);
}

/**
* Send the "volumeDown" command
* @category Control
*/
async volumeDown(): Promise<void> {
await this._pressKey(NodePyATVInternalKeys.volumeDown);
await this._pressKey(NodePyATVInternalKeys.volumeDown, NodePyATVExecutableType.atvscript);
}

/**
* Send the "volumeUp" command
* @category Control
*/
async volumeUp(): Promise<void> {
await this._pressKey(NodePyATVInternalKeys.volumeUp);
await this._pressKey(NodePyATVInternalKeys.volumeUp, NodePyATVExecutableType.atvscript);
}

/**
Expand All @@ -526,7 +530,7 @@ export default class NodePyATVDevice implements EventEmitter{
* @deprecated
*/
async wakeup(): Promise<void> {
await this._pressKey(NodePyATVInternalKeys.wakeup);
await this._pressKey(NodePyATVInternalKeys.wakeup, NodePyATVExecutableType.atvscript);
}

/**
Expand Down

0 comments on commit 7e6eefa

Please sign in to comment.