9 Commits

Author SHA1 Message Date
fb260c5532 Bump rev 2019-08-15 16:02:29 -04:00
f903c40f9c 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
2019-08-13 21:02:40 -04:00
5c69e7b11f Cleaned up unused code. Corrected issue with getActive 2019-08-09 17:25:24 -04:00
a67674b3d3 deploy script now builds 2019-08-09 17:25:03 -04:00
f682c0e380 Added deployment script 2019-08-01 19:21:46 -04:00
14312908bf Added redundant matrix calls 2019-08-01 18:57:19 -04:00
152d73e9f9 Fixed UseMatrix being a string instead of boolean. This fixed listen to music activity. 2019-07-31 17:34:23 -04:00
727c8ceba7 Fixed issue where inputs weren't getting set. Possibly fixed incorrect tv issue. 2019-07-31 17:14:02 -04:00
39f4a7c1bc Enabled debugging support
# Conflicts:
#	src/DataProviders/HarmonyDataProvider.ts
2019-07-31 16:33:31 -04:00
10 changed files with 218 additions and 426 deletions

View File

@ -1,7 +1,7 @@
{ {
"bridge": { "bridge": {
"name": "Homebridge", "name": "Homebridge",
"username": "CC:22:3D:E3:CE:42", "username": "CC:22:3D:E3:CE:74",
"port": 51826, "port": 51826,
"pin": "031-45-154" "pin": "031-45-154"
}, },
@ -13,10 +13,8 @@
}, },
{ {
"platform": "HarmonyHubMatrix", "platform": "HarmonyHubMatrix",
"harmonyHubIp": "192.168.1.14", "hubIp": "192.168.1.14",
"neeoHubIp": "192.168.1.24",
"Matrix": { "Matrix": {
"Hub": "Harmony",
"DeviceName": "Gefen AV Switch", "DeviceName": "Gefen AV Switch",
"Inputs": [ "Inputs": [
{ {
@ -59,17 +57,14 @@
"DisplayName": "Chromecast", "DisplayName": "Chromecast",
"DeviceSetupList": [ "DeviceSetupList": [
{ {
"Hub": "Harmony",
"DeviceName": "LG TV", "DeviceName": "LG TV",
"Input": "HDMI1" "Input": "Hdmi1"
}, },
{ {
"Hub": "Harmony",
"DeviceName": "JVC AV Receiver", "DeviceName": "JVC AV Receiver",
"Input": "DVD" "Input": "Dvd"
}, },
{ {
"Hub": "Harmony",
"DeviceName": "Chromecast", "DeviceName": "Chromecast",
"Input": [] "Input": []
} }
@ -83,19 +78,16 @@
"DisplayName": "Play Xbox One", "DisplayName": "Play Xbox One",
"DeviceSetupList": [ "DeviceSetupList": [
{ {
"Hub": "Harmony",
"DeviceName": "Microsoft Xbox One", "DeviceName": "Microsoft Xbox One",
"Input": [] "Input": []
}, },
{ {
"Hub": "Harmony",
"DeviceName": "LG TV", "DeviceName": "LG TV",
"Input": "HDMI1" "Input": "Hdmi1"
}, },
{ {
"Hub": "Harmony",
"DeviceName": "JVC AV Receiver", "DeviceName": "JVC AV Receiver",
"Input": "DVD" "Input": "Dvd"
} }
], ],
"VolumeDevice": "JVC AV Receiver", "VolumeDevice": "JVC AV Receiver",
@ -107,19 +99,16 @@
"DisplayName": "Play PS4", "DisplayName": "Play PS4",
"DeviceSetupList": [ "DeviceSetupList": [
{ {
"Hub": "Harmony",
"DeviceName": "Sony PS4", "DeviceName": "Sony PS4",
"Input": [] "Input": []
}, },
{ {
"Hub": "Harmony",
"DeviceName": "LG TV", "DeviceName": "LG TV",
"Input": "HDMI1" "Input": "Hdmi1"
}, },
{ {
"Hub": "Harmony",
"DeviceName": "JVC AV Receiver", "DeviceName": "JVC AV Receiver",
"Input": "DVD" "Input": "Dvd"
} }
], ],
"VolumeDevice": "JVC AV Receiver", "VolumeDevice": "JVC AV Receiver",
@ -131,19 +120,16 @@
"DisplayName": "Apple TV", "DisplayName": "Apple TV",
"DeviceSetupList": [ "DeviceSetupList": [
{ {
"Hub": "Harmony",
"DeviceName": "Apple TV Gen 4", "DeviceName": "Apple TV Gen 4",
"Input": [] "Input": []
}, },
{ {
"Hub": "Harmony",
"DeviceName": "LG TV", "DeviceName": "LG TV",
"Input": "HDMI1" "Input": "Hdmi1"
}, },
{ {
"Hub": "Harmony",
"DeviceName": "JVC AV Receiver", "DeviceName": "JVC AV Receiver",
"Input": "DVD" "Input": "Dvd"
} }
], ],
"VolumeDevice": "JVC AV Receiver", "VolumeDevice": "JVC AV Receiver",
@ -155,9 +141,8 @@
"DisplayName": "Listen to Music", "DisplayName": "Listen to Music",
"DeviceSetupList": [ "DeviceSetupList": [
{ {
"Hub": "Harmony",
"DeviceName": "JVC AV Receiver", "DeviceName": "JVC AV Receiver",
"Input": "DVD" "Input": "CD"
} }
], ],
"VolumeDevice": "JVC AV Receiver", "VolumeDevice": "JVC AV Receiver",
@ -174,22 +159,19 @@
"DisplayName": "Chromecast", "DisplayName": "Chromecast",
"DeviceSetupList": [ "DeviceSetupList": [
{ {
"Hub": "Neeo",
"DeviceName": "Vizio TV", "DeviceName": "Vizio TV",
"Input": "HDMI1" "Input": "Hdmi1"
}, },
{ {
"Hub": "Neeo", "DeviceName": "Harman Kardon AV Receiver",
"DeviceName": "Harmon Kardon Receicer",
"Input": "Game" "Input": "Game"
}, },
{ {
"Hub": "Harmony",
"DeviceName": "Chromecast", "DeviceName": "Chromecast",
"Input": [] "Input": []
} }
], ],
"VolumeDevice": "Harmon Kardon Receicer", "VolumeDevice": "Harman Kardon AV Receiver",
"ControlDevice": "Chromecast", "ControlDevice": "Chromecast",
"OutputDevice": "Vizio TV", "OutputDevice": "Vizio TV",
"UseMatrix": "true" "UseMatrix": "true"
@ -198,22 +180,19 @@
"DisplayName": "Play Xbox One", "DisplayName": "Play Xbox One",
"DeviceSetupList": [ "DeviceSetupList": [
{ {
"Hub": "Harmony",
"DeviceName": "Microsoft Xbox One", "DeviceName": "Microsoft Xbox One",
"Input": [] "Input": []
}, },
{ {
"Hub": "Neeo",
"DeviceName": "Vizio TV", "DeviceName": "Vizio TV",
"Input": "HDMI1" "Input": "Hdmi1"
}, },
{ {
"Hub": "Neeo", "DeviceName": "Harman Kardon AV Receiver",
"DeviceName": "Harmon Kardon Receicer",
"Input": "Game" "Input": "Game"
} }
], ],
"VolumeDevice": "Harmon Kardon Receicer", "VolumeDevice": "Harman Kardon AV Receiver",
"ControlDevice": "Microsoft Xbox One", "ControlDevice": "Microsoft Xbox One",
"OutputDevice": "Vizio TV", "OutputDevice": "Vizio TV",
"UseMatrix": "true" "UseMatrix": "true"
@ -222,22 +201,19 @@
"DisplayName": "Play PS4", "DisplayName": "Play PS4",
"DeviceSetupList": [ "DeviceSetupList": [
{ {
"Hub": "Harmony",
"DeviceName": "Sony PS4", "DeviceName": "Sony PS4",
"Input": [] "Input": []
}, },
{ {
"Hub": "Neeo",
"DeviceName": "Vizio TV", "DeviceName": "Vizio TV",
"Input": "HDMI1" "Input": "Hdmi1"
}, },
{ {
"Hub": "Neeo", "DeviceName": "Harman Kardon AV Receiver",
"DeviceName": "Harmon Kardon Receicer", "Input": "Dvd"
"Input": "DVD"
} }
], ],
"VolumeDevice": "Harmon Kardon Receicer", "VolumeDevice": "Harman Kardon AV Receiver",
"ControlDevice": "Sony PS4", "ControlDevice": "Sony PS4",
"OutputDevice": "LG TV", "OutputDevice": "LG TV",
"UseMatrix": "true" "UseMatrix": "true"
@ -246,22 +222,19 @@
"DisplayName": "Apple TV", "DisplayName": "Apple TV",
"DeviceSetupList": [ "DeviceSetupList": [
{ {
"Hub": "Harmony",
"DeviceName": "Apple TV Gen 4", "DeviceName": "Apple TV Gen 4",
"Input": [] "Input": []
}, },
{ {
"Hub": "Neeo",
"DeviceName": "Vizio TV", "DeviceName": "Vizio TV",
"Input": "HDMI1" "Input": "Hdmi1"
}, },
{ {
"Hub": "Neeo", "DeviceName": "Harman Kardon AV Receiver",
"DeviceName": "Harmon Kardon Receicer",
"Input": "Game" "Input": "Game"
} }
], ],
"VolumeDevice": "Harmon Kardon Receicer", "VolumeDevice": "Harman Kardon AV Receiver",
"ControlDevice": "Apple TV Gen 4", "ControlDevice": "Apple TV Gen 4",
"OutputDevice": "Vizio TV", "OutputDevice": "Vizio TV",
"UseMatrix": "true" "UseMatrix": "true"
@ -275,14 +248,12 @@
"DisplayName": "Chromecast", "DisplayName": "Chromecast",
"DeviceSetupList": [ "DeviceSetupList": [
{ {
"Hub": "Harmony",
"DeviceName": "Chromecast", "DeviceName": "Chromecast",
"Input": [] "Input": []
}, },
{ {
"Hub": "Harmony",
"DeviceName": "Westinghouse TV", "DeviceName": "Westinghouse TV",
"Input": "HDMI1" "Input": "Hdmi1"
} }
], ],
"VolumeDevice": "Westinghouse TV", "VolumeDevice": "Westinghouse TV",
@ -294,14 +265,12 @@
"DisplayName": "Watch Apple Tv", "DisplayName": "Watch Apple Tv",
"DeviceSetupList": [ "DeviceSetupList": [
{ {
"Hub": "Harmony",
"DeviceName": "Apple TV Gen 4", "DeviceName": "Apple TV Gen 4",
"Input": [] "Input": []
}, },
{ {
"Hub": "Harmony",
"DeviceName": "Westinghouse TV", "DeviceName": "Westinghouse TV",
"Input": "HDMI1" "Input": "Hdmi1"
} }
], ],
"VolumeDevice": "Westinghouse TV", "VolumeDevice": "Westinghouse TV",
@ -313,12 +282,10 @@
"DisplayName": "Play Xbox One", "DisplayName": "Play Xbox One",
"DeviceSetupList": [ "DeviceSetupList": [
{ {
"Hub": "Harmony",
"DeviceName": "Westinghouse TV", "DeviceName": "Westinghouse TV",
"Input": "HDMI1" "Input": "Hdmi1"
}, },
{ {
"Hub": "Harmony",
"DeviceName": "Microsoft Xbox One", "DeviceName": "Microsoft Xbox One",
"Input": [] "Input": []
} }

22
deploy.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
remote_user="bmw"
remote_server="192.168.1.31"
deploy_location="/home/bmw/homebridge-harmony-control"
homebridge_location="/var/lib/homebridge/"
#build
tsc --build
#copy files to remote machine
scp -r bin $remote_user@$remote_server:$deploy_location
scp package.json $remote_user@$remote_server:$deploy_location
#install package
ssh -t $remote_user@$remote_server "sudo npm install -g --unsafe-perm $deploy_location"
#restart service
ssh -t
ssh -t $remote_user@$remote_server "sudo systemctl restart homebridge.service"
ssh -t $remote_user@$remote_server "sudo systemctl status homebridge.service"
echo done
exit

13
package-lock.json generated
View File

@ -748,14 +748,6 @@
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.0.7.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-12.0.7.tgz",
"integrity": "sha512-1YKeT4JitGgE4SOzyB9eMwO0nGVNkNEsm9qlIt1Lqm/tG2QEiSMTD4kS3aO6L+w5SClLVxALmIBESK6Mk5wX0A==" "integrity": "sha512-1YKeT4JitGgE4SOzyB9eMwO0nGVNkNEsm9qlIt1Lqm/tG2QEiSMTD4kS3aO6L+w5SClLVxALmIBESK6Mk5wX0A=="
}, },
"@types/node-fetch": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.5.0.tgz",
"integrity": "sha512-TLFRywthBgL68auWj+ziWu+vnmmcHCDFC/sqCOQf1xTz4hRq8cu79z8CtHU9lncExGBsB8fXA4TiLDLt6xvMzw==",
"requires": {
"@types/node": "*"
}
},
"ajv": { "ajv": {
"version": "6.10.0", "version": "6.10.0",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.10.0.tgz", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.10.0.tgz",
@ -1549,11 +1541,6 @@
"resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz", "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz",
"integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==" "integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg=="
}, },
"node-fetch": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
"integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA=="
},
"node-persist": { "node-persist": {
"version": "0.0.8", "version": "0.0.8",
"resolved": "https://registry.npmjs.org/node-persist/-/node-persist-0.0.8.tgz", "resolved": "https://registry.npmjs.org/node-persist/-/node-persist-0.0.8.tgz",

View File

@ -1,6 +1,6 @@
{ {
"name": "homebridge-harmony-control", "name": "homebridge-harmony-control",
"version": "1.0.0", "version": "1.0.2",
"description": "Homebridge platform to control smart home equipment by room.", "description": "Homebridge platform to control smart home equipment by room.",
"main": "bin/index.js", "main": "bin/index.js",
"scripts": { "scripts": {
@ -35,10 +35,8 @@
"@babel/preset-env": "^7.4.5", "@babel/preset-env": "^7.4.5",
"@babel/preset-typescript": "^7.3.3", "@babel/preset-typescript": "^7.3.3",
"@types/node": "^12.0.7", "@types/node": "^12.0.7",
"@types/node-fetch": "^2.5.0",
"harmony-websocket": "^1.1.0", "harmony-websocket": "^1.1.0",
"homebridge": "^0.4.50", "homebridge": "^0.4.50",
"node-fetch": "^2.6.0",
"request": "^2.88.0" "request": "^2.88.0"
} }
} }

View File

@ -2,7 +2,7 @@ import { Activity } from '../Models/Activity';
import { Matrix } from '../Models/Matrix'; import { Matrix } from '../Models/Matrix';
import { IAccessory } from './IAccessory'; import { IAccessory } from './IAccessory';
import callbackify from '../Util/Callbackify'; import callbackify from '../Util/Callbackify';
import HubDataProvider from '../DataProviders/HubDataProvider'; import HarmonyDataProvider from '../DataProviders/HarmonyDataProvider';
let Service: HAPNodeJS.Service; let Service: HAPNodeJS.Service;
let Characteristic: HAPNodeJS.Characteristic; let Characteristic: HAPNodeJS.Characteristic;
@ -29,13 +29,12 @@ export enum RemoteKey {
} }
export interface IControlUnitProps { export interface IControlUnitProps {
dataProvider: HubDataProvider, dataProvider: HarmonyDataProvider,
displayName: string, displayName: string,
activities: Array<Activity>, activities: Array<Activity>,
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;
@ -58,7 +56,7 @@ export class ControlUnit implements IAccessory {
//Harmony fields //Harmony fields
private activities: Array<Activity> = []; private activities: Array<Activity> = [];
private dataProvider: HubDataProvider; private dataProvider: HarmonyDataProvider;
public platformAccessory: any; public platformAccessory: any;
@ -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;
@ -134,11 +131,10 @@ export class ControlUnit implements IAccessory {
.on("get", callbackify(this.onGetAccessoryActive)); .on("get", callbackify(this.onGetAccessoryActive));
//Set remote characteristics if is external //Set remote characteristics if is external
if (this.isExternal) {
this.televisionService.getCharacteristic(Characteristic.RemoteKey) this.televisionService.getCharacteristic(Characteristic.RemoteKey)
//@ts-ignore //@ts-ignore
.on("set", callbackify(this.onSetRemoteKey)); .on("set", callbackify(this.onSetRemoteKey));
}
this.televisionService.getCharacteristic(Characteristic.ActiveIdentifier) this.televisionService.getCharacteristic(Characteristic.ActiveIdentifier)
//@ts-ignore //@ts-ignore
@ -151,40 +147,34 @@ 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(this.name) ? 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) => {
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]);
} }
}
/** /**
* Event handler for GET active identifier characteristic * Event handler for GET active identifier characteristic
@ -233,29 +223,11 @@ 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;
} }
} }
}
/*********************
*
* Information Service
*
********************/
/**
* Configure information service
*/
private configureAccessoryInformation(): void {
this.informationService = new Service.AccessoryInformation(this.displayName, 'information');
this.informationService
.setCharacteristic(Characteristic.Manufacturer, 'Loftux Carwings')
.setCharacteristic(Characteristic.Model, 'Heater-Cooler')
}
/***************** /*****************
* *

View File

@ -1,69 +1,58 @@
import { Activity } from "../Models/Activity"; import { Activity } from "../Models/Activity";
import { DeviceSetupItem } from "../Models/DeviceSetupItem"; import { DeviceSetupItem } from "../Models/DeviceSetupItem";
import { Input, Matrix, Output } from "../Models/Matrix"; import { Input, Matrix, Output } from "../Models/Matrix";
import { IDevice } from './IDevice';
import { RemoteKey } from '../Accessories/ControlUnit'; import { RemoteKey } from '../Accessories/ControlUnit';
import { sleep } from '../Util/Sleep'; import { sleep } from '../Util/Sleep';
import { hub } from "..";
import fetch from 'node-fetch';
let Characteristic: HAPNodeJS.Characteristic; let Characteristic: HAPNodeJS.Characteristic;
const Harmony = require("harmony-websocket"); const Harmony = require("harmony-websocket");
interface IDevice {
id: string,
name: string,
supportsCommand(commandName: string): boolean,
getCommand(commandName: string): string,
commands: { [name: string]: string };
on: boolean;
}
interface IActivityState { interface IActivityState {
currentActivity: Activity currentActivity: Activity
} }
interface IHubDataProviderProps { interface IHarmonyDataProviderProps {
harmonyHubAddress: string, hubAddress: string,
neeoHubAddress: string,
log: any, log: any,
matrix: Matrix matrix: Matrix
} }
interface INeeoMacro { class HarmonyDataProvider {
roomKey: string, private harmony: any;
macroKey: string,
deviceKey: string,
}
class HubDataProvider {
//Harmony Fields
private harmonyHubAddress: string;
private harmonyConnected: boolean = false;
//Neeo Fields
private neeoHubAddress: string;
//Common Fields
private log: any; private log: any;
private hubAddress: string = "";
private connected: boolean = false;
private devices: { [name: string]: IDevice; } = {}; private devices: { [name: string]: IDevice; } = {};
private states: { [controlUnitName: string]: (IActivityState | undefined) } = {}; private states: { [controlUnitName: string]: (IActivityState | undefined) } = {};
private matrix: Matrix; private matrix: Matrix;
constructor(props: IHubDataProviderProps) { constructor(props: IHarmonyDataProviderProps) {
this.log = props.log; this.log = props.log;
this.harmonyHubAddress = props.harmonyHubAddress; this.hubAddress = props.hubAddress;
this.neeoHubAddress = props.neeoHubAddress;
this.matrix = props.matrix; this.matrix = props.matrix;
if (this.harmonyHubAddress) { this.harmony = new Harmony();
try {
Promise.resolve(this.connectHarmony(this.harmonyHubAddress)); //Listeners
} catch (err) { this.harmony.on('open', () => {
this.log(`Error connecting to harmony hub at ${this.harmonyHubAddress}: ${err}`); this.connected = true;
} });
} this.harmony.on('close', () => {
if (this.neeoHubAddress) { this.connected = false;
try { });
Promise.resolve(this.connectNeeo(this.neeoHubAddress));
} catch (err) { this.connect();
this.log(`Error connecting to neeo hub at ${this.neeoHubAddress}: ${err}`)
}
}
} }
/** /**
@ -87,21 +76,16 @@ class HubDataProvider {
//Build potential list of devices to turn off //Build potential list of devices to turn off
let devicesToTurnOff: Array<IDevice> = this.states[controlUnitName]!.currentActivity.deviceSetupItems let devicesToTurnOff: Array<IDevice> = this.states[controlUnitName]!.currentActivity.deviceSetupItems
.map((value: DeviceSetupItem): IDevice => { .map((value: DeviceSetupItem): IDevice => {
return this.getDeviceFromName(value.deviceName, value.hubType); return this.getDeviceFromName(value.deviceName);
}); });
//Resolve device conflicts with other controlUnits //Resolve device conflicts with other controlUnits
devicesToTurnOff = this.sanitizeDeviceList(devicesToTurnOff, controlUnitName); devicesToTurnOff = this.sanitizeDeviceList(devicesToTurnOff, controlUnitName);
await Promise.all(
//Turn off devices //Turn off devices
devicesToTurnOff.map(async (device: IDevice) => { devicesToTurnOff.forEach((device: IDevice) => {
if (device) { this.powerOffDevice(device);
await device.powerOff(); });
}
})
);
this.states[controlUnitName] = undefined; this.states[controlUnitName] = undefined;
} }
@ -118,7 +102,7 @@ class HubDataProvider {
//Build potential list of devices to to turn on //Build potential list of devices to to turn on
let devicesToTurnOn: Array<IDevice> = activity.deviceSetupItems.map((value: DeviceSetupItem): IDevice => { let devicesToTurnOn: Array<IDevice> = activity.deviceSetupItems.map((value: DeviceSetupItem): IDevice => {
return this.getDeviceFromName(value.deviceName, value.hubType); return this.getDeviceFromName(value.deviceName);
}); });
//Resolve device conflicts with other controlUnits //Resolve device conflicts with other controlUnits
@ -126,10 +110,10 @@ class HubDataProvider {
//Turn on devices //Turn on devices
await Promise.all(devicesToTurnOn.map(async (device: IDevice) => { await Promise.all(devicesToTurnOn.map(async (device: IDevice) => {
if (device && device.name) { if (device && device.name && this.devices[device.name]) {
if (!device.on) { if (!device.on) {
this.log(`Turning on device ${device.name}`) this.log(`Turning on device ${device.name}`)
await device.powerOn(); await this.powerOnDevice(device);
} }
} }
})); }));
@ -137,11 +121,11 @@ class HubDataProvider {
//Assign correct input //Assign correct input
await Promise.all( await Promise.all(
activity.deviceSetupItems.map(async (value: DeviceSetupItem) => { activity.deviceSetupItems.map(async (value: DeviceSetupItem) => {
let device: IDevice = this.getDeviceFromName(value.deviceName, value.hubType); let device: IDevice = this.getDeviceFromName(value.deviceName);
if (device && device.supportsCommand(`Input${value.input}`)) { if (device && device.supportsCommand(`Input${value.input}`)) {
let command: string = device.getCommand(`Input${value.input}`); let command: string = device.getCommand(`Input${value.input}`);
await device.sendCommand(command); await this.sendCommand(command);
} }
}) })
); );
@ -154,19 +138,21 @@ class HubDataProvider {
let inputCommandName: string = `In ${input.inputNumber}`; let inputCommandName: string = `In ${input.inputNumber}`;
let outputCommandName: string = `Out ${output.outputLetter}`; let outputCommandName: string = `Out ${output.outputLetter}`;
let matrixDevice: IDevice = this.getDeviceFromName(this.matrix.deviceName, this.matrix.hubType); let matrixDevice: IDevice = this.getDeviceFromName(this.matrix.deviceName);
//Route hdmi //Route hdmi
if (matrixDevice.supportsCommand(inputCommandName) && matrixDevice.supportsCommand(outputCommandName)) { if (matrixDevice.supportsCommand(inputCommandName) && matrixDevice.supportsCommand(outputCommandName)) {
await matrixDevice.sendCommand(matrixDevice.getCommand(inputCommandName)); await this.sendCommand(matrixDevice.getCommand(outputCommandName));
await matrixDevice.sendCommand(matrixDevice.getCommand(outputCommandName)); await this.sendCommand(matrixDevice.getCommand(inputCommandName));
await this.sendCommand(matrixDevice.getCommand(outputCommandName));
await this.sendCommand(matrixDevice.getCommand(inputCommandName));
} }
} }
//Build potential list of devices to turn off //Build potential list of devices to turn off
if (lastActivity) { if (lastActivity) {
let devicesToTurnOff: Array<IDevice> = lastActivity.deviceSetupItems.map((value: DeviceSetupItem): IDevice => { let devicesToTurnOff: Array<IDevice> = lastActivity.deviceSetupItems.map((value: DeviceSetupItem): IDevice => {
return this.getDeviceFromName(value.deviceName, value.hubType); return this.getDeviceFromName(value.deviceName);
}); });
//remove devices that will be used for next activity from list //remove devices that will be used for next activity from list
@ -190,7 +176,7 @@ class HubDataProvider {
if (device) { if (device) {
if (device.on) { if (device.on) {
this.log(`Turning off device ${device.name}`) this.log(`Turning off device ${device.name}`)
await device.powerOff(); await this.powerOffDevice(device);
} }
} }
}) })
@ -207,13 +193,10 @@ class HubDataProvider {
*/ */
public volumeUp = async (controlUnitName: string) => { public volumeUp = async (controlUnitName: string) => {
let volumeUpCommand: string = "Volume Up" let volumeUpCommand: string = "Volume Up"
let currentActivity: Activity = this.states[controlUnitName]!.currentActivity;
let deviceSetupItem: DeviceSetupItem = currentActivity.deviceSetupItems.filter(e => e.deviceName == currentActivity.volumeDeviceId)[0];
if (this.states[controlUnitName]) { if (this.states[controlUnitName]) {
let volumeDevice: IDevice = this.getDeviceFromName(currentActivity.volumeDeviceId, deviceSetupItem.hubType); let volumeDevice: IDevice = this.getDeviceFromName(this.states[controlUnitName]!.currentActivity.volumeDeviceId);
if (volumeDevice.supportsCommand(volumeUpCommand)) { if (volumeDevice.supportsCommand(volumeUpCommand)) {
volumeDevice.sendCommand(volumeDevice.getCommand(volumeUpCommand)); this.sendCommand(volumeDevice.getCommand(volumeUpCommand));
} }
} }
} }
@ -223,52 +206,14 @@ class HubDataProvider {
*/ */
public volumeDown = async (controlUnitName: string) => { public volumeDown = async (controlUnitName: string) => {
let volumeDownCommand: string = "Volume Down" let volumeDownCommand: string = "Volume Down"
let currentActivity: Activity = this.states[controlUnitName]!.currentActivity;
let deviceSetupItem: DeviceSetupItem = currentActivity.deviceSetupItems.filter(e => e.deviceName == currentActivity.volumeDeviceId)[0];
if (this.states[controlUnitName]) { if (this.states[controlUnitName]) {
let volumeDevice: IDevice = this.getDeviceFromName(currentActivity.volumeDeviceId, deviceSetupItem.hubType); let volumeDevice: IDevice = this.getDeviceFromName(this.states[controlUnitName]!.currentActivity.volumeDeviceId);
if (volumeDevice.supportsCommand(volumeDownCommand)) { if (volumeDevice.supportsCommand(volumeDownCommand)) {
volumeDevice.sendCommand(volumeDevice.getCommand(volumeDownCommand)); this.sendCommand(volumeDevice.getCommand(volumeDownCommand));
} }
} }
} }
/**
* Return if a control unit is active
* @param controlUnitName
*/
public getIsActive(controlUnitName: string): Activity | undefined {
return this.states[controlUnitName] ? this.states[controlUnitName]!.currentActivity : undefined;
}
/**
* Helper function to make sure no control unit depends on device list.
* @param devicesToTurnOn The list of devices to modify.
* @param controlUnitName The name of the control unit in question.
*/
private sanitizeDeviceList(devicesToTurnOn: Array<IDevice>, controlUnitName: string): Array<IDevice> {
for (let controlUnitKey in this.states) {
//Skip self
if (controlUnitKey === controlUnitName) {
continue;
}
let currentOtherState: IActivityState = this.states[controlUnitKey]!;
if (currentOtherState) {
currentOtherState.currentActivity.deviceSetupItems.forEach((value: DeviceSetupItem) => {
//there are devices to remove
if (devicesToTurnOn.some(e => e && e.name === value.deviceName)) {
let deviceToRemove: IDevice = devicesToTurnOn.filter(i => i.name === value.deviceName)[0];
delete devicesToTurnOn[devicesToTurnOn.indexOf(deviceToRemove)];
}
});
}
}
return devicesToTurnOn;
}
/** /**
* Send key press for current activity. * Send key press for current activity.
* *
@ -279,10 +224,7 @@ class HubDataProvider {
if (this.states[controlUnitName]) { if (this.states[controlUnitName]) {
let commandName: string = ""; let commandName: string = "";
let currentActivity: Activity = this.states[controlUnitName]!.currentActivity; let device: IDevice = this.getDeviceFromName(this.states[controlUnitName]!.currentActivity.controlDeviceId);
let deviceSetupItem: DeviceSetupItem = currentActivity.deviceSetupItems.filter(e => e.deviceName == currentActivity.volumeDeviceId)[0];
let device: IDevice = this.getDeviceFromName(this.states[controlUnitName]!.currentActivity.controlDeviceId, deviceSetupItem.hubType);
switch (key) { switch (key) {
case RemoteKey.ARROW_UP: { case RemoteKey.ARROW_UP: {
commandName = "Direction Up"; commandName = "Direction Up";
@ -323,54 +265,43 @@ class HubDataProvider {
} }
if (device && device.supportsCommand(commandName)) { if (device && device.supportsCommand(commandName)) {
device.sendCommand(device.getCommand(commandName)); this.sendCommand(device.getCommand(commandName));
} }
} }
} }
/** /**
* Get the IDevice by name. * Return if a control unit is active
* @param deviceName The device to retrieve. * @param controlUnitName
*/ */
private getDeviceFromName(deviceName: string, hubType: hub): IDevice { public getIsActive(controlUnitName: string): Activity | undefined {
return this.devices[`${hubType}-${deviceName}`]; return this.states[controlUnitName] ? this.states[controlUnitName]!.currentActivity : undefined;
} }
/** /**
* Connect to harmony hub and receive device info. * Connect to harmony and receive device info
*/ */
private connectHarmony = async (address: string): Promise<void> => { private connect = async () => {
let harmony: any = new Harmony(); await this.harmony.connect(this.hubAddress);
//Listeners
harmony.on('open', () => {
this.harmonyConnected = true;
});
harmony.on('close', () => {
this.harmonyConnected = false;
});
await harmony.connect(address);
let self = this; let self = this;
setTimeout(async function () { setTimeout(async function () {
if (self.harmonyConnected) { if (self.connected) {
let devices: any = await harmony.getDevices(); let devices: any = await self.harmony.getDevices();
try { try {
await Promise.all( await Promise.all(
//Add each to dictionary //Add each to dictionary
devices.map(async (dev: any) => { devices.map(async (dev: any) => {
//get commands //get commands
let commands: { [name: string]: string } = {}; let commands: { [name: string]: string } = {};
let deviceCommands: any = await harmony.getDeviceCommands(dev.id); let deviceCommands: any = await self.harmony.getDeviceCommands(dev.id);
deviceCommands.forEach((command: any) => { deviceCommands.forEach((command: any) => {
commands[command.label] = command.action; commands[command.label] = command.action;
}); });
self.devices[`Harmony-${dev.label}`] = { self.devices[dev.label] = {
id: dev.id, id: dev.id,
name: dev.label, name: dev.label,
commands: commands, commands: commands,
harmony: harmony,
hubType: "Harmony",
log: self.log,
on: false, on: false,
//Define device methods //Define device methods
supportsCommand(commandName: string): boolean { supportsCommand(commandName: string): boolean {
@ -379,39 +310,6 @@ class HubDataProvider {
}, },
getCommand(commandName: string): string { getCommand(commandName: string): string {
return commands[commandName]; return commands[commandName];
},
async powerOn(): Promise<void> {
let powerOnCommand: string = "Power On";
let powerToggleCommand: string = "Power Toggle";
if (this.supportsCommand(powerOnCommand)) {
await this.sendCommand(this.getCommand(powerOnCommand));
this.on = true;
} else if (this.supportsCommand(powerToggleCommand)) {
await this.sendCommand(this.getCommand(powerToggleCommand));
this.on = true;
}
},
async powerOff(): Promise<void> {
let powerOffCommand: string = "Power Off";
let powerToggleCommand: string = "Power Toggle";
if (this.supportsCommand(powerOffCommand)) {
await this.sendCommand(this.getCommand(powerOffCommand));
this.on = false;
} else if (this.supportsCommand(powerToggleCommand)) {
await this.sendCommand(this.getCommand(powerToggleCommand));
this.on = false;
}
},
async sendCommand(command: string): Promise<void> {
try {
//Execute command
let response = await this.harmony.sendCommand(JSON.stringify(command));
//Sleep
await sleep(800);
} catch (err) {
this.log(`ERROR - error sending command to harmony: ${err}`);
}
} }
} }
})); }));
@ -424,85 +322,87 @@ class HubDataProvider {
}, 1000); }, 1000);
} }
private connectNeeo = async (address: string): Promise<void> => { /**
* Power off a device (Power toggle if no power off).
let baseUrl = `http://${address}:3000/v1/projects/home`; */
private powerOffDevice = async (device: IDevice) => {
let response: any = await fetch(`${baseUrl}/rooms`);
let rooms: { [key: string]: any } = await response.json();
function regularizeString(str: string) {
str = str.toLowerCase();
return str.replace(/(?:^|\s)\S/g, function (a) { return a.toUpperCase(); });
}
for (let key in rooms) {
let devices: { [key: string]: any } = rooms[key].devices;
for (let deviceKey in devices) {
let device = devices[deviceKey];
//shape commands from macros
let commands: { [item: string]: any } = {};
for (let macroKey in device.macros) {
let macro: any = device.macros[macroKey];
commands[regularizeString(macro.name)] = {
deviceKey: macro.deviceKey,
macroKey: macro.key,
roomKey: macro.roomKey,
};
}
this.devices[`Neeo-${deviceKey}`] = {
id: device.key,
name: device.name,
log: this.log,
hubType: "Neeo",
commands: commands,
on: false,
supportsCommand(commandName: string): boolean {
let command = this.commands[commandName];
return (command) ? true : false;
},
getCommand(commandName: string): string {
return this.commands[commandName];
},
async sendCommand(command: string): Promise<void> {
if (this.supportsCommand(command)) {
let macro: INeeoMacro = this.commands[command];
let url: string = `${baseUrl}/rooms/${macro.roomKey}/devices/${macro.deviceKey}/macros/${macro.macroKey}/trigger`;
this.log(`Sending command ${url}`);
fetch(`${baseUrl}/rooms/${macro.roomKey}/devices/${macro.deviceKey}/macros/${macro.macroKey}/trigger`);
}
},
async powerOn(): Promise<void> {
let powerOnCommand: string = "Power On";
let powerToggleCommand: string = "Power Toggle";
if (this.supportsCommand(powerOnCommand)) {
await this.sendCommand(powerOnCommand);
this.on = true;
} else if (this.supportsCommand(powerToggleCommand)) {
await this.sendCommand(powerToggleCommand);
this.on = true;
}
},
async powerOff(): Promise<void> {
let powerOffCommand: string = "Power Off"; let powerOffCommand: string = "Power Off";
let powerToggleCommand: string = "Power Toggle"; let powerToggleCommand: string = "Power Toggle";
if (this.supportsCommand(powerOffCommand)) { if (device && device.supportsCommand(powerOffCommand)) {
await this.sendCommand(powerOffCommand); await this.sendCommand(device.getCommand(powerOffCommand));
this.on = false; device.on = false;
} else if (this.supportsCommand(powerToggleCommand)) { } else if (device && device.supportsCommand(powerToggleCommand)) {
await this.sendCommand(powerToggleCommand); await this.sendCommand(device.getCommand(powerToggleCommand));
this.on = false; device.on = false;
}
}
}
}
}
} }
} }
export default HubDataProvider; /**
* Power on a device (Power toggle if no power on).
*/
private powerOnDevice = async (device: IDevice) => {
let powerOnCommand: string = "Power On";
let powerToggleCommand: string = "Power Toggle";
if (device && device.supportsCommand(powerOnCommand)) {
await this.sendCommand(device.getCommand(powerOnCommand));
device.on = true;
} else if (device && device.supportsCommand(powerToggleCommand)) {
await this.sendCommand(device.getCommand(powerToggleCommand));
device.on = true;
}
}
/**
* Get the IDevice by name.
* @param deviceName The device to retrieve.
*/
private getDeviceFromName(deviceName: string): IDevice {
return this.devices[deviceName];
}
/**
* Helper function to make sure no control unit depends on device list.
* @param devicesToTurnOn The list of devices to modify.
* @param controlUnitName The name of the control unit in question.
*/
private sanitizeDeviceList(devicesToTurnOn: Array<IDevice>, controlUnitName: string): Array<IDevice> {
for (let controlUnitKey in this.states) {
//Skip self
if (controlUnitKey === controlUnitName) {
continue;
}
let currentOtherState: IActivityState = this.states[controlUnitKey]!;
if (currentOtherState) {
currentOtherState.currentActivity.deviceSetupItems.forEach((value: DeviceSetupItem) => {
//there are devices to remove
if (devicesToTurnOn.some(e => e && e.name === value.deviceName)) {
let deviceToRemove: IDevice = devicesToTurnOn.filter(i => i.name === value.deviceName)[0];
delete devicesToTurnOn[devicesToTurnOn.indexOf(deviceToRemove)];
}
});
}
}
return devicesToTurnOn;
}
/**
* Send a command to the harmony hub.
* @param command The command to send.
*/
private sendCommand = async (command: string) => {
try {
//Execute command
let response = await this.harmony.sendCommand(JSON.stringify(command));
//Sleep
await sleep(800);
} catch (err) {
this.log(`ERROR - error sending command to harmony: ${err}`);
}
}
}
export default HarmonyDataProvider;

View File

@ -1,16 +0,0 @@
import { hub } from "..";
export interface IDevice {
id: string,
name: string,
harmony?: any,
log: any,
hubType: hub
supportsCommand(commandName: string): boolean,
getCommand(commandName: string): string,
sendCommand(command: string): void,
powerOn(): Promise<void>,
powerOff(): Promise<void>,
commands: { [name: string]: any };
on: boolean;
}

View File

@ -1,9 +1,7 @@
import { hub } from "..";
export interface IDeviceSetupItemProps { export interface IDeviceSetupItemProps {
deviceName: string, deviceName: string,
input: string, input: string
hub: hub
} }
/** /**
@ -12,11 +10,9 @@ export interface IDeviceSetupItemProps {
export class DeviceSetupItem { export class DeviceSetupItem {
private _deviceId: string = ""; private _deviceId: string = "";
private _input: string = ""; private _input: string = "";
private _hubType: hub;
constructor(props: IDeviceSetupItemProps) { constructor(props: IDeviceSetupItemProps) {
this._deviceId = props.deviceName; this._deviceId = props.deviceName;
this._input = props.input; this._input = props.input;
this._hubType = props.hub;
} }
public get deviceName() { public get deviceName() {
@ -26,8 +22,4 @@ export class DeviceSetupItem {
public get input() { public get input() {
return this._input; return this._input;
} }
public get hubType() {
return this._hubType;
}
} }

View File

@ -1,10 +1,7 @@
import { hub } from "..";
export interface IMatrixProps { export interface IMatrixProps {
inputs: Array<Input>, inputs: Array<Input>,
outputs: Array<Output>, outputs: Array<Output>,
deviceName: string, deviceName: string,
hubType: hub
} }
export interface Input { export interface Input {
@ -24,13 +21,11 @@ export class Matrix {
private _inputs: Array<Input> = []; private _inputs: Array<Input> = [];
private _outputs: Array<Output> = []; private _outputs: Array<Output> = [];
private _deviceName: string; private _deviceName: string;
private _hubType: hub = "Harmony";
constructor(props: IMatrixProps) { constructor(props: IMatrixProps) {
this._inputs = props.inputs; this._inputs = props.inputs;
this._outputs = props.outputs; this._outputs = props.outputs;
this._deviceName = props.deviceName; this._deviceName = props.deviceName;
this._hubType = props.hubType;
} }
public get inputs(): Array<Input> { public get inputs(): Array<Input> {
@ -44,8 +39,4 @@ export class Matrix {
public get deviceName(): string { public get deviceName(): string {
return this._deviceName; return this._deviceName;
} }
public get hubType(): hub {
return this._hubType;
}
} }

View File

@ -2,13 +2,11 @@ import { ControlUnit } from "./Accessories/ControlUnit";
import { Activity } from "./Models/Activity"; import { Activity } from "./Models/Activity";
import { DeviceSetupItem } from "./Models/DeviceSetupItem"; import { DeviceSetupItem } from "./Models/DeviceSetupItem";
import { Input, Output, Matrix } from "./Models/Matrix"; import { Input, Output, Matrix } from "./Models/Matrix";
import HubDataProvider from './DataProviders/HubDataProvider'; import HarmonyDataProvider from "./DataProviders/HarmonyDataProvider";
let Accessory: any; let Accessory: any;
let Homebridge: any; let Homebridge: any;
export type hub = "Harmony" | "Neeo";
/** /**
* Main entry. * Main entry.
* @param homebridge * @param homebridge
@ -28,8 +26,8 @@ class HarmonyMatrixPlatform {
log: any = {}; log: any = {};
config: any = {}; config: any = {};
api: any; api: any;
externalAccessories: Array<any> = []; dataProvider: HarmonyDataProvider | null;
dataProvider: HubDataProvider | null; controlUnits: Array<ControlUnit> = [];
constructor(log: any, config: any, api: any) { constructor(log: any, config: any, api: any) {
this.log = log; this.log = log;
@ -50,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]);
}) })
@ -62,14 +60,12 @@ class HarmonyMatrixPlatform {
*/ */
accessories(callback: (accessories: Array<ControlUnit>) => void) { accessories(callback: (accessories: Array<ControlUnit>) => void) {
//Parse ip //Parse ip
let harmonyIp: string = this.config["harmonyHubIp"]; let hubIp: string = this.config["hubIp"];
let neeoIp: string = this.config["neeoHubIp"];
//Parse matrix //Parse matrix
let configInputs: any = this.config["Matrix"]["Inputs"]; let configInputs: any = this.config["Matrix"]["Inputs"];
let configOutputs: any = this.config["Matrix"]["Outputs"]; let configOutputs: any = this.config["Matrix"]["Outputs"];
let matrixName: string = this.config["Matrix"]["DeviceName"]; let matrixName: string = this.config["Matrix"]["DeviceName"];
let hub: hub = this.config["Matrix"]["Hub"];
let inputs: Array<Input> = []; let inputs: Array<Input> = [];
let outputs: Array<Output> = []; let outputs: Array<Output> = [];
@ -102,20 +98,18 @@ class HarmonyMatrixPlatform {
inputs: inputs, inputs: inputs,
outputs: outputs, outputs: outputs,
deviceName: matrixName, deviceName: matrixName,
hubType: hub
}); });
//construct data provider //construct data provider
this.dataProvider = new HubDataProvider({ this.dataProvider = new HarmonyDataProvider({
harmonyHubAddress: harmonyIp, hubAddress: hubIp,
neeoHubAddress: neeoIp,
matrix: matrix, matrix: matrix,
log: this.log log: this.log
}); });
//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"];
@ -128,8 +122,7 @@ class HarmonyMatrixPlatform {
//Add device //Add device
devices.push(new DeviceSetupItem({ devices.push(new DeviceSetupItem({
deviceName: configDevice["DeviceName"], deviceName: configDevice["DeviceName"],
input: configDevice["Input"], input: configDevice["Input"]
hub: configDevice["Hub"]
})); }));
this.log(`INFO - Added device '${configDevice["DeviceName"]}' for activity '${configActivity["DisplayName"]}'`); this.log(`INFO - Added device '${configDevice["DeviceName"]}' for activity '${configActivity["DisplayName"]}'`);
}); });
@ -140,7 +133,7 @@ class HarmonyMatrixPlatform {
controlDeviceId: configActivity["ControlDevice"], controlDeviceId: configActivity["ControlDevice"],
outputDeviceId: configActivity["OutputDevice"], outputDeviceId: configActivity["OutputDevice"],
displayName: configActivity["DisplayName"], displayName: configActivity["DisplayName"],
useMatrix: configActivity["UseMatrix"], useMatrix: configActivity["UseMatrix"] === "true" ? true : false,
deviceList: devices deviceList: devices
})); }));
this.log(`INFO - Added activity '${configActivity["DisplayName"]}'`); this.log(`INFO - Added activity '${configActivity["DisplayName"]}'`);
@ -153,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);
} }
} }