Merge branch 'feature/neeo_control'

This commit is contained in:
watsonb8 2019-07-26 15:44:53 -04:00
commit 9b48614dd1
3 changed files with 48 additions and 13 deletions

View File

@ -35,6 +35,7 @@ export interface IControlUnitProps {
api: any, api: any,
log: any, log: any,
homebridge: any, homebridge: any,
isExternal: boolean,
} }
/** /**
@ -47,6 +48,7 @@ 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;
@ -70,15 +72,16 @@ export class ControlUnit implements IAccessory {
Api = props.api; Api = props.api;
Service = props.api.hap.Service; Service = props.api.hap.Service;
Characteristic = props.api.hap.Characteristic; Characteristic = props.api.hap.Characteristic;
this.displayName = props.displayName; this.name = props.displayName;
this.name = this.displayName; this.displayName = props.isExternal ? `${props.displayName}-Remote` : props.displayName;
this.isExternal = props.isExternal;
this.activities = props.activities; this.activities = props.activities;
this.dataProvider = props.dataProvider; this.dataProvider = props.dataProvider;
homebridge = props.homebridge; 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 //Configure services
this.configureTvService(); this.configureTvService();
@ -142,25 +145,35 @@ 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;
} }
} }
}
/** /**
* Event handler for GET active characteristic * Event handler for GET active characteristic
*/ */
private onGetAccessoryActive = async () => { private onGetAccessoryActive = async () => {
//@ts-ignore //@ts-ignore
return this.dataProvider.getIsActive ? Characteristic.Active.Active : Characteristic.Active.Inactive return this.dataProvider.getIsActive() ? Characteristic.Active.Active : Characteristic.Active.Inactive
} }
/** /**
* Event handler for SET remote key * Event handler for SET remote key
*/ */
private onSetRemoteKey = async (key: any) => { 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); this.dataProvider.sendKeyPress(this.name, key);
} }
@ -168,8 +181,10 @@ export class ControlUnit implements IAccessory {
* 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]);
} }
}
/** /**
* Event handler for GET active identifier characteristic * Event handler for GET active identifier characteristic

View File

@ -221,6 +221,7 @@ class HarmonyDataProvider {
public sendKeyPress = async (controlUnitName: string, key: any) => { public sendKeyPress = async (controlUnitName: string, key: any) => {
if (this.states[controlUnitName]) { if (this.states[controlUnitName]) {
let commandName: string = ""; let commandName: string = "";
let device: IDevice = this.getDeviceFromName(this.states[controlUnitName]!.currentActivity.controlDeviceId); let device: IDevice = this.getDeviceFromName(this.states[controlUnitName]!.currentActivity.controlDeviceId);
switch (key) { switch (key) {
case RemoteKey.ARROW_UP: { case RemoteKey.ARROW_UP: {

View File

@ -27,6 +27,7 @@ class HarmonyMatrixPlatform {
config: any = {}; config: any = {};
api: any; api: any;
externalAccessories: Array<any> = []; externalAccessories: Array<any> = [];
dataProvider: HarmonyDataProvider | null;
constructor(log: any, config: any, api: any) { constructor(log: any, config: any, api: any) {
this.log = log; this.log = log;
@ -34,10 +35,14 @@ class HarmonyMatrixPlatform {
this.api = api; this.api = api;
this.log('INFO - Registering Harmony Matrix Platform'); this.log('INFO - Registering Harmony Matrix Platform');
this.api.on('didFinishLaunching', this.didFinishLaunching.bind(this)); this.api.on('didFinishLaunching', this.didFinishLaunching.bind(this));
this.dataProvider = null;
this.log("This is new");
} }
/** /**
* Handler for didFinishLaunching * Handler for didFinishLaunching
* Happens after constructor
*/ */
didFinishLaunching() { didFinishLaunching() {
this.log(`Publishing external accessories`); this.log(`Publishing external accessories`);
@ -96,7 +101,7 @@ class HarmonyMatrixPlatform {
}); });
//construct data provider //construct data provider
let dataProvider = new HarmonyDataProvider({ this.dataProvider = new HarmonyDataProvider({
hubAddress: hubIp, hubAddress: hubIp,
matrix: matrix, matrix: matrix,
log: this.log log: this.log
@ -135,23 +140,37 @@ class HarmonyMatrixPlatform {
}); });
let controlUnit: ControlUnit = new ControlUnit({ let controlUnit: ControlUnit = new ControlUnit({
dataProvider: dataProvider, dataProvider: this.dataProvider!,
displayName: configControlUnit["DisplayName"], displayName: configControlUnit["DisplayName"],
api: this.api, api: this.api,
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
let externalAccessory = controlUnitExternal as homebridge.platformAccessory;
//Add control unit //Add control unit
controlUnits.push(accessory); controlUnits.push(accessory);
//Add to list of remotes
this.externalAccessories.push(externalAccessory);
this.log(`INFO - Added ControlUnit`); this.log(`INFO - Added ControlUnit`);
}); });
this.externalAccessories = controlUnits;
callback(controlUnits); callback(controlUnits);
} }
} }