Working remote
This commit is contained in:
@ -3,6 +3,8 @@ import { DeviceSetupItem } from "../Models/DeviceSetupItem";
|
||||
import { threadId } from "worker_threads";
|
||||
import { Input, Matrix, Output } from "../Models/Matrix";
|
||||
|
||||
let Characteristic: HAPNodeJS.Characteristic;
|
||||
|
||||
const Harmony = require("harmony-websocket");
|
||||
interface IDevice {
|
||||
id: string,
|
||||
@ -17,6 +19,22 @@ interface IActivityState {
|
||||
currentActivity: Activity
|
||||
}
|
||||
|
||||
export enum RemoteKey {
|
||||
REWIND = 0,
|
||||
FAST_FORWARD = 1,
|
||||
NEXT_TRACK = 2,
|
||||
PREVIOUS_TRACK = 3,
|
||||
ARROW_UP = 4,
|
||||
ARROW_DOWN = 5,
|
||||
ARROW_LEFT = 6,
|
||||
ARROW_RIGHT = 7,
|
||||
SELECT = 8,
|
||||
BACK = 9,
|
||||
EXIT = 10,
|
||||
PLAY_PAUSE = 11,
|
||||
INFORMATION = 15,
|
||||
}
|
||||
|
||||
interface IHarmonyDataProviderProps {
|
||||
hubAddress: string,
|
||||
log: any,
|
||||
@ -53,7 +71,11 @@ class HarmonyDataProvider {
|
||||
}
|
||||
|
||||
public powerOn = async (controlUnitName: string, activity: Activity) => {
|
||||
await this.startActivity(controlUnitName, activity);
|
||||
//Only power on if not alread on
|
||||
let currentActivity = this.states[controlUnitName] ? this.states[controlUnitName]!.currentActivity : undefined;
|
||||
if (!currentActivity) {
|
||||
await this.startActivity(controlUnitName, activity);
|
||||
}
|
||||
}
|
||||
|
||||
public powerOff = async (controlUnitName: string) => {
|
||||
@ -78,6 +100,7 @@ class HarmonyDataProvider {
|
||||
}
|
||||
|
||||
public startActivity = async (controlUnitName: string, activity: Activity) => {
|
||||
this.log(`Starting activity ${activity.displayName} for controlUnit: ${controlUnitName}`)
|
||||
let lastActivity: Activity | undefined = undefined;
|
||||
if (this.states[controlUnitName]) {
|
||||
lastActivity = this.states[controlUnitName]!.currentActivity;
|
||||
@ -189,8 +212,62 @@ class HarmonyDataProvider {
|
||||
}
|
||||
}
|
||||
|
||||
public sendKeyPress = async (controlUnitName: string) => {
|
||||
public sendKeyPress = async (controlUnitName: string, key: any) => {
|
||||
if (this.states[controlUnitName]) {
|
||||
let commandName: string = "";
|
||||
let device: IDevice = this.getDeviceFromName(this.states[controlUnitName]!.currentActivity.controlDeviceId);
|
||||
switch (key) {
|
||||
//@ts-ignore
|
||||
case RemoteKey.ARROW_UP: {
|
||||
commandName = "Direction Up";
|
||||
break;
|
||||
}
|
||||
//@ts-ignore
|
||||
case RemoteKey.ARROW_DOWN: {
|
||||
commandName = "Direction Down";
|
||||
break;
|
||||
}
|
||||
//@ts-ignore
|
||||
case RemoteKey.ARROW_LEFT: {
|
||||
commandName = "Direction Left";
|
||||
break;
|
||||
}
|
||||
//@ts-ignore
|
||||
case RemoteKey.ARROW_RIGHT: {
|
||||
commandName = "Direction Right";
|
||||
break;
|
||||
}
|
||||
//@ts-ignore
|
||||
case RemoteKey.SELECT: {
|
||||
commandName = "Select";
|
||||
break;
|
||||
}
|
||||
//@ts-ignore
|
||||
case RemoteKey.PLAY_PAUSE: {
|
||||
commandName = "Pause";
|
||||
break;
|
||||
}
|
||||
//@ts-ignore
|
||||
case RemoteKey.INFORMATION: {
|
||||
commandName = "Menu";
|
||||
break;
|
||||
}
|
||||
//@ts-ignore
|
||||
case RemoteKey.BACK: {
|
||||
commandName = "Back";
|
||||
break;
|
||||
}
|
||||
//@ts-ignore
|
||||
case RemoteKey.EXIT: {
|
||||
commandName = "Back";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (device && device.supportsCommand(commandName)) {
|
||||
this.sendCommand(device.getCommand(commandName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public getIsActive(controlUnitName: string): Activity | undefined {
|
||||
@ -217,7 +294,6 @@ class HarmonyDataProvider {
|
||||
deviceCommands.forEach((command: any) => {
|
||||
commands[command.label] = command.action;
|
||||
});
|
||||
|
||||
self.devices[dev.label] = {
|
||||
id: dev.id,
|
||||
name: dev.label,
|
||||
|
Reference in New Issue
Block a user