From f0eb57e4dc510e7d95260c0065b342ff3d86bcb5 Mon Sep 17 00:00:00 2001 From: watsonb8 Date: Wed, 24 Jul 2019 16:19:23 -0400 Subject: [PATCH 1/3] Commands only send if the activity has already been started. --- src/DataProviders/HarmonyDataProvider.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/DataProviders/HarmonyDataProvider.ts b/src/DataProviders/HarmonyDataProvider.ts index 75b1012..0b34624 100644 --- a/src/DataProviders/HarmonyDataProvider.ts +++ b/src/DataProviders/HarmonyDataProvider.ts @@ -221,6 +221,12 @@ class HarmonyDataProvider { public sendKeyPress = async (controlUnitName: string, key: any) => { if (this.states[controlUnitName]) { let commandName: string = ""; + + //Ignore commands unless the tv is already on + if (!this.states[controlUnitName]!.currentActivity) { + return; + } + let device: IDevice = this.getDeviceFromName(this.states[controlUnitName]!.currentActivity.controlDeviceId); switch (key) { case RemoteKey.ARROW_UP: { From 7638644935eca9d58440e11f004e926855c8afe7 Mon Sep 17 00:00:00 2001 From: watsonb8 Date: Fri, 26 Jul 2019 13:07:50 -0400 Subject: [PATCH 2/3] Modifying to publish new external accessory to fix remote problem (untested) --- src/Accessories/ControlUnit.ts | 15 ++++++++++----- src/index.ts | 26 ++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/Accessories/ControlUnit.ts b/src/Accessories/ControlUnit.ts index 2bcd7f4..2ee8e13 100644 --- a/src/Accessories/ControlUnit.ts +++ b/src/Accessories/ControlUnit.ts @@ -35,6 +35,7 @@ export interface IControlUnitProps { api: any, log: any, homebridge: any, + isExternal: boolean, } /** @@ -47,6 +48,7 @@ export class ControlUnit implements IAccessory { //fields private log: any = {}; private displayName: string = ""; + private isExternal: boolean = false; //Service fields private televisionService: HAPNodeJS.Service | undefined; @@ -72,6 +74,7 @@ export class ControlUnit implements IAccessory { Characteristic = props.api.hap.Characteristic; this.displayName = props.displayName; this.name = this.displayName; + this.isExternal = props.isExternal; this.activities = props.activities; @@ -142,10 +145,12 @@ export class ControlUnit implements IAccessory { * Event handler for SET active characteristic */ private onSetAccessoryActive = async (value: any) => { - switch (value) { - case 0: this.dataProvider.powerOff(this.name); break; - //Turn on with first activity - case 1: this.dataProvider.powerOn(this.name, this.activities[0]); break; + if (!this.isExternal) { + switch (value) { + case 0: this.dataProvider.powerOff(this.name); break; + //Turn on with first activity + case 1: this.dataProvider.powerOn(this.name, this.activities[0]); break; + } } } @@ -154,7 +159,7 @@ export class ControlUnit implements IAccessory { */ private onGetAccessoryActive = async () => { //@ts-ignore - return this.dataProvider.getIsActive ? Characteristic.Active.Active : Characteristic.Active.Inactive + return this.dataProvider.getIsActive() ? Characteristic.Active.Active : Characteristic.Active.Inactive } /** diff --git a/src/index.ts b/src/index.ts index cb21140..bb63c41 100644 --- a/src/index.ts +++ b/src/index.ts @@ -27,6 +27,7 @@ class HarmonyMatrixPlatform { config: any = {}; api: any; externalAccessories: Array = []; + dataProvider: HarmonyDataProvider | null; constructor(log: any, config: any, api: any) { this.log = log; @@ -34,10 +35,13 @@ class HarmonyMatrixPlatform { this.api = api; this.log('INFO - Registering Harmony Matrix Platform'); this.api.on('didFinishLaunching', this.didFinishLaunching.bind(this)); + + this.dataProvider = null; } /** * Handler for didFinishLaunching + * Happens after constructor */ didFinishLaunching() { this.log(`Publishing external accessories`); @@ -96,7 +100,7 @@ class HarmonyMatrixPlatform { }); //construct data provider - let dataProvider = new HarmonyDataProvider({ + this.dataProvider = new HarmonyDataProvider({ hubAddress: hubIp, matrix: matrix, log: this.log @@ -135,23 +139,37 @@ class HarmonyMatrixPlatform { }); let controlUnit: ControlUnit = new ControlUnit({ - dataProvider: dataProvider, + dataProvider: this.dataProvider!, displayName: configControlUnit["DisplayName"], api: this.api, log: this.log, activities: activities, - homebridge: Homebridge + homebridge: Homebridge, + isExternal: false + }); + + let controlUnitExternal: ControlUnit = new ControlUnit({ + dataProvider: this.dataProvider!, + displayName: `${configControlUnit["DisplayName"]}-Remote`, + api: this.api, + log: this.log, + activities: activities, + homebridge: Homebridge, + isExternal: true }); //@ts-ignore let accessory = controlUnit as homebridge.platformAccessory; + //@ts-ignore + let externalAccessory = controlUnitExternal as homebridge.platformAccessory; //Add control unit controlUnits.push(accessory); + //Add to list of remotes + this.externalAccessories.push(externalAccessory); this.log(`INFO - Added ControlUnit`); }); - this.externalAccessories = controlUnits; callback(controlUnits); } } \ No newline at end of file From 04024d565d80aa9ee85dee3477a18abfa95f00e7 Mon Sep 17 00:00:00 2001 From: watsonb8 Date: Fri, 26 Jul 2019 15:44:26 -0400 Subject: [PATCH 3/3] Fixed issue with Tv's turning on while using remote --- src/Accessories/ControlUnit.ts | 18 ++++++++++++++---- src/DataProviders/HarmonyDataProvider.ts | 5 ----- src/index.ts | 3 ++- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Accessories/ControlUnit.ts b/src/Accessories/ControlUnit.ts index 2ee8e13..f834729 100644 --- a/src/Accessories/ControlUnit.ts +++ b/src/Accessories/ControlUnit.ts @@ -72,8 +72,8 @@ export class ControlUnit implements IAccessory { Api = props.api; Service = props.api.hap.Service; Characteristic = props.api.hap.Characteristic; - this.displayName = props.displayName; - this.name = this.displayName; + this.name = props.displayName; + this.displayName = props.isExternal ? `${props.displayName}-Remote` : props.displayName; this.isExternal = props.isExternal; this.activities = props.activities; @@ -81,7 +81,7 @@ export class ControlUnit implements IAccessory { this.dataProvider = props.dataProvider; homebridge = props.homebridge; - this.platformAccessory = new homebridge.platformAccessory(this.name, this.generateUUID(), homebridge.hap.Accessory.Categories.TELEVISION); + this.platformAccessory = new homebridge.platformAccessory(this.displayName, this.generateUUID(), homebridge.hap.Accessory.Categories.TELEVISION); //Configure services this.configureTvService(); @@ -166,6 +166,14 @@ export class ControlUnit implements IAccessory { * Event handler for SET remote key */ private onSetRemoteKey = async (key: any) => { + //Set the active identifier with every key press + let currentActivity: Activity = this.dataProvider.getIsActive(this.name)!; + let identifier: number = 0; + if (currentActivity) { + identifier = this.activities.findIndex(e => e.displayName === currentActivity.displayName); + } + this.televisionService!.setCharacteristic(Characteristic.ActiveIdentifier, identifier); + this.dataProvider.sendKeyPress(this.name, key); } @@ -173,7 +181,9 @@ export class ControlUnit implements IAccessory { * Event handler for SET active identifier characteristic */ private onSetActiveIdentifier = async (identifier: any) => { - this.dataProvider.startActivity(this.name, this.activities[identifier]); + if (!this.isExternal) { + this.dataProvider.startActivity(this.name, this.activities[identifier]); + } } /** diff --git a/src/DataProviders/HarmonyDataProvider.ts b/src/DataProviders/HarmonyDataProvider.ts index 0b34624..40d8684 100644 --- a/src/DataProviders/HarmonyDataProvider.ts +++ b/src/DataProviders/HarmonyDataProvider.ts @@ -222,11 +222,6 @@ class HarmonyDataProvider { if (this.states[controlUnitName]) { let commandName: string = ""; - //Ignore commands unless the tv is already on - if (!this.states[controlUnitName]!.currentActivity) { - return; - } - let device: IDevice = this.getDeviceFromName(this.states[controlUnitName]!.currentActivity.controlDeviceId); switch (key) { case RemoteKey.ARROW_UP: { diff --git a/src/index.ts b/src/index.ts index bb63c41..313dd6a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -37,6 +37,7 @@ class HarmonyMatrixPlatform { this.api.on('didFinishLaunching', this.didFinishLaunching.bind(this)); this.dataProvider = null; + this.log("This is new"); } /** @@ -150,7 +151,7 @@ class HarmonyMatrixPlatform { let controlUnitExternal: ControlUnit = new ControlUnit({ dataProvider: this.dataProvider!, - displayName: `${configControlUnit["DisplayName"]}-Remote`, + displayName: `${configControlUnit["DisplayName"]}`, api: this.api, log: this.log, activities: activities,