Working remote

This commit is contained in:
watsonb8 2019-06-16 22:36:15 -04:00
parent ed8f126a34
commit 5040435760
2 changed files with 83 additions and 13 deletions

View File

@ -123,7 +123,6 @@ export class ControlUnit implements IAccessory {
* Event handler for SET active characteristic * Event handler for SET active characteristic
*/ */
private onSetAccessoryActive = async (value: any) => { private onSetAccessoryActive = async (value: any) => {
this.log(`set active + ${value}`);
switch (value) { switch (value) {
case 0: this.dataProvider.powerOff(this.name); break; case 0: this.dataProvider.powerOff(this.name); break;
//Turn on with first activity //Turn on with first activity
@ -135,22 +134,21 @@ export class ControlUnit implements IAccessory {
* Event handler for GET active characteristic * Event handler for GET active characteristic
*/ */
private onGetAccessoryActive = async () => { private onGetAccessoryActive = async () => {
this.log(`get active`)
//@ts-ignore //@ts-ignore
return this.dataProvider.getIsActive ? Characteristic.Active.Active : Characteristic.Active.Inactive return this.dataProvider.getIsActive ? Characteristic.Active.Active : Characteristic.Active.Inactive
} }
//TODO /**
* Event handler for SET remote key
*/
private onSetRemoteKey = async (key: any) => { private onSetRemoteKey = async (key: any) => {
this.log(`set remote key + ${key}`); this.dataProvider.sendKeyPress(this.name, key);
} }
/** /**
* Event handler for SET active identifier characteristic * Event handler for SET active identifier characteristic
*/ */
private onSetActiveIdentifier = async (identifier: any) => { private onSetActiveIdentifier = async (identifier: any) => {
this.log(`set active identifier + ${identifier}`);
this.dataProvider.startActivity(this.name, this.activities[identifier]); this.dataProvider.startActivity(this.name, this.activities[identifier]);
} }
@ -158,7 +156,6 @@ export class ControlUnit implements IAccessory {
* Event handler for GET active identifier characteristic * Event handler for GET active identifier characteristic
*/ */
private onGetActiveIdentifier = async () => { private onGetActiveIdentifier = async () => {
this.log(`get active identifier`);
let currentActivity: Activity = this.dataProvider.getIsActive(this.name)!; let currentActivity: Activity = this.dataProvider.getIsActive(this.name)!;
let identifier: number = 0; let identifier: number = 0;
if (currentActivity) { if (currentActivity) {
@ -202,7 +199,6 @@ export class ControlUnit implements IAccessory {
* Event handler for SET volume characteristic * Event handler for SET volume characteristic
*/ */
private onSetVolumeSelector = async (value: any) => { private onSetVolumeSelector = async (value: any) => {
this.log(`set volume + ${value}`);
switch (value) { switch (value) {
case 0: this.dataProvider.volumeUp(this.name); break; case 0: this.dataProvider.volumeUp(this.name); break;
case 1: this.dataProvider.volumeDown(this.name); break; case 1: this.dataProvider.volumeDown(this.name); break;
@ -237,7 +233,6 @@ export class ControlUnit implements IAccessory {
private configureInputSourceService(): void { private configureInputSourceService(): void {
let inputs: Array<HAPNodeJS.Service> = []; let inputs: Array<HAPNodeJS.Service> = [];
this.activities.forEach((activity: Activity, index: number) => { this.activities.forEach((activity: Activity, index: number) => {
this.log(activity.displayName);
let inputService = new Service.InputSource(activity.displayName, 'activity' + activity.displayName); let inputService = new Service.InputSource(activity.displayName, 'activity' + activity.displayName);
inputService inputService
.setCharacteristic(Characteristic.Identifier, index) .setCharacteristic(Characteristic.Identifier, index)
@ -277,7 +272,6 @@ export class ControlUnit implements IAccessory {
* Called by homebridge to gather services for this accessory. * Called by homebridge to gather services for this accessory.
*/ */
getServices(): Array<HAPNodeJS.Service> { getServices(): Array<HAPNodeJS.Service> {
this.log(`${this.displayName}`)
let services: Array<HAPNodeJS.Service> = [this.televisionService!, this.televisionSpeakerService!]; let services: Array<HAPNodeJS.Service> = [this.televisionService!, this.televisionSpeakerService!];
this.inputServices.forEach((service: HAPNodeJS.Service | undefined) => { this.inputServices.forEach((service: HAPNodeJS.Service | undefined) => {
services.push(service!); services.push(service!);

View File

@ -3,6 +3,8 @@ import { DeviceSetupItem } from "../Models/DeviceSetupItem";
import { threadId } from "worker_threads"; import { threadId } from "worker_threads";
import { Input, Matrix, Output } from "../Models/Matrix"; import { Input, Matrix, Output } from "../Models/Matrix";
let Characteristic: HAPNodeJS.Characteristic;
const Harmony = require("harmony-websocket"); const Harmony = require("harmony-websocket");
interface IDevice { interface IDevice {
id: string, id: string,
@ -17,6 +19,22 @@ interface IActivityState {
currentActivity: Activity 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 { interface IHarmonyDataProviderProps {
hubAddress: string, hubAddress: string,
log: any, log: any,
@ -53,7 +71,11 @@ class HarmonyDataProvider {
} }
public powerOn = async (controlUnitName: string, activity: Activity) => { 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) => { public powerOff = async (controlUnitName: string) => {
@ -78,6 +100,7 @@ class HarmonyDataProvider {
} }
public startActivity = async (controlUnitName: string, activity: Activity) => { public startActivity = async (controlUnitName: string, activity: Activity) => {
this.log(`Starting activity ${activity.displayName} for controlUnit: ${controlUnitName}`)
let lastActivity: Activity | undefined = undefined; let lastActivity: Activity | undefined = undefined;
if (this.states[controlUnitName]) { if (this.states[controlUnitName]) {
lastActivity = this.states[controlUnitName]!.currentActivity; 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 { public getIsActive(controlUnitName: string): Activity | undefined {
@ -217,7 +294,6 @@ class HarmonyDataProvider {
deviceCommands.forEach((command: any) => { deviceCommands.forEach((command: any) => {
commands[command.label] = command.action; commands[command.label] = command.action;
}); });
self.devices[dev.label] = { self.devices[dev.label] = {
id: dev.id, id: dev.id,
name: dev.label, name: dev.label,