Getting rid of externalAccessories.

Rolling back external accessories specifically for remote because this was causing an unpredictable crash. (Likely an unhandled exception within either apple framework or HAPNodeJS
This commit is contained in:
watsonb8 2019-08-13 21:02:40 -04:00
parent 5c69e7b11f
commit f903c40f9c
2 changed files with 15 additions and 40 deletions

View File

@ -35,7 +35,6 @@ export interface IControlUnitProps {
api: any, api: any,
log: any, log: any,
homebridge: any, homebridge: any,
isExternal: boolean,
} }
/** /**
@ -48,7 +47,6 @@ export class ControlUnit implements IAccessory {
//fields //fields
private log: any = {}; private log: any = {};
private displayName: string = ""; private displayName: string = "";
private isExternal: boolean = false;
//Service fields //Service fields
private televisionService: HAPNodeJS.Service | undefined; private televisionService: HAPNodeJS.Service | undefined;
@ -73,8 +71,7 @@ export class ControlUnit implements IAccessory {
Service = props.api.hap.Service; Service = props.api.hap.Service;
Characteristic = props.api.hap.Characteristic; Characteristic = props.api.hap.Characteristic;
this.name = props.displayName; this.name = props.displayName;
this.displayName = props.isExternal ? `${props.displayName}-Remote` : props.displayName; this.displayName = props.displayName;
this.isExternal = props.isExternal;
this.activities = props.activities; this.activities = props.activities;
@ -150,12 +147,10 @@ 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) => {
if (!this.isExternal) { 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 case 1: this.dataProvider.powerOn(this.name, this.activities[0]); break;
case 1: this.dataProvider.powerOn(this.name, this.activities[0]); break;
}
} }
} }
@ -171,18 +166,14 @@ export class ControlUnit implements IAccessory {
* Event handler for SET remote key * Event handler for SET remote key
*/ */
private onSetRemoteKey = async (key: any) => { private onSetRemoteKey = async (key: any) => {
if (this.isExternal) { this.dataProvider.sendKeyPress(this.name, 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) => {
if (!this.isExternal) { this.dataProvider.startActivity(this.name, this.activities[identifier]);
this.dataProvider.startActivity(this.name, this.activities[identifier]);
}
} }
/** /**
@ -232,11 +223,9 @@ 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) => {
if (this.isExternal) { 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;
}
} }
} }

View File

@ -26,8 +26,8 @@ class HarmonyMatrixPlatform {
log: any = {}; log: any = {};
config: any = {}; config: any = {};
api: any; api: any;
externalAccessories: Array<any> = [];
dataProvider: HarmonyDataProvider | null; dataProvider: HarmonyDataProvider | null;
controlUnits: Array<ControlUnit> = [];
constructor(log: any, config: any, api: any) { constructor(log: any, config: any, api: any) {
this.log = log; this.log = log;
@ -48,7 +48,7 @@ class HarmonyMatrixPlatform {
this.log(`Publishing external accessories`); this.log(`Publishing external accessories`);
//This is required in order to have multiple tv remotes on one platform //This is required in order to have multiple tv remotes on one platform
this.externalAccessories.forEach((accessory: ControlUnit) => { this.controlUnits.forEach((accessory: ControlUnit) => {
this.api.publishExternalAccessories("HarmonyMatrixPlatform", [accessory.platformAccessory]); this.api.publishExternalAccessories("HarmonyMatrixPlatform", [accessory.platformAccessory]);
}) })
@ -109,7 +109,7 @@ class HarmonyMatrixPlatform {
//Parse control units //Parse control units
let configControlUnits: any = this.config["ControlUnits"]; let configControlUnits: any = this.config["ControlUnits"];
let controlUnits: Array<ControlUnit> = [];
configControlUnits.forEach((configControlUnit: any) => { configControlUnits.forEach((configControlUnit: any) => {
//Parse activities list //Parse activities list
let configActivities: any = configControlUnit["Activities"]; let configActivities: any = configControlUnit["Activities"];
@ -146,31 +146,17 @@ class HarmonyMatrixPlatform {
log: this.log, log: this.log,
activities: activities, activities: activities,
homebridge: Homebridge, homebridge: Homebridge,
isExternal: false
});
let controlUnitExternal: ControlUnit = new ControlUnit({
dataProvider: this.dataProvider!,
displayName: `${configControlUnit["DisplayName"]}`,
api: this.api,
log: this.log,
activities: activities,
homebridge: Homebridge,
isExternal: true
}); });
//@ts-ignore //@ts-ignore
let accessory = controlUnit as homebridge.platformAccessory; let accessory = controlUnit as homebridge.platformAccessory;
//@ts-ignore //@ts-ignore
let externalAccessory = controlUnitExternal as homebridge.platformAccessory;
//Add control unit //Add control unit
controlUnits.push(accessory); this.controlUnits.push(accessory);
//Add to list of remotes
this.externalAccessories.push(externalAccessory);
this.log(`INFO - Added ControlUnit`); this.log(`INFO - Added ControlUnit`);
}); });
callback(controlUnits); callback(this.controlUnits);
} }
} }