16 Commits
1.0.0 ... 1.0.2

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
73cba09edb Disabled features for default remote 2019-07-26 16:30:57 -04:00
9b48614dd1 Merge branch 'feature/neeo_control' 2019-07-26 15:44:53 -04:00
04024d565d Fixed issue with Tv's turning on while using remote 2019-07-26 15:44:26 -04:00
7638644935 Modifying to publish new external accessory to fix remote problem (untested) 2019-07-26 13:07:50 -04:00
f0eb57e4dc Commands only send if the activity has already been started. 2019-07-24 16:19:23 -04:00
0ea4188487 Added a delay between commands. Fixed issue where inputs were not being set correctly. 2019-06-23 11:42:10 -04:00
8bb65b5b3c Code cleanup. Added comments. 2019-06-17 15:59:15 -04:00
14 changed files with 196 additions and 82 deletions

16
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"preLaunchTask": "build and install",
"program": "/Users/brandonwatson/.npm-global/bin/homebridge",
"sourceMaps": true,
}
]
}

17
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,17 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "build",
"problemMatcher": []
},
{
"type": "shell",
"label": "build and install",
"command": "npm run build&&sudo npm install -g --unsafe-perm ."
}
]
}

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"
}, },
@ -58,11 +58,11 @@
"DeviceSetupList": [ "DeviceSetupList": [
{ {
"DeviceName": "LG TV", "DeviceName": "LG TV",
"Input": "HDMI1" "Input": "Hdmi1"
}, },
{ {
"DeviceName": "JVC AV Receiver", "DeviceName": "JVC AV Receiver",
"Input": "DVD" "Input": "Dvd"
}, },
{ {
"DeviceName": "Chromecast", "DeviceName": "Chromecast",
@ -83,11 +83,11 @@
}, },
{ {
"DeviceName": "LG TV", "DeviceName": "LG TV",
"Input": "HDMI1" "Input": "Hdmi1"
}, },
{ {
"DeviceName": "JVC AV Receiver", "DeviceName": "JVC AV Receiver",
"Input": "DVD" "Input": "Dvd"
} }
], ],
"VolumeDevice": "JVC AV Receiver", "VolumeDevice": "JVC AV Receiver",
@ -104,11 +104,11 @@
}, },
{ {
"DeviceName": "LG TV", "DeviceName": "LG TV",
"Input": "HDMI1" "Input": "Hdmi1"
}, },
{ {
"DeviceName": "JVC AV Receiver", "DeviceName": "JVC AV Receiver",
"Input": "DVD" "Input": "Dvd"
} }
], ],
"VolumeDevice": "JVC AV Receiver", "VolumeDevice": "JVC AV Receiver",
@ -125,11 +125,11 @@
}, },
{ {
"DeviceName": "LG TV", "DeviceName": "LG TV",
"Input": "HDMI1" "Input": "Hdmi1"
}, },
{ {
"DeviceName": "JVC AV Receiver", "DeviceName": "JVC AV Receiver",
"Input": "DVD" "Input": "Dvd"
} }
], ],
"VolumeDevice": "JVC AV Receiver", "VolumeDevice": "JVC AV Receiver",
@ -142,7 +142,7 @@
"DeviceSetupList": [ "DeviceSetupList": [
{ {
"DeviceName": "JVC AV Receiver", "DeviceName": "JVC AV Receiver",
"Input": "DVD" "Input": "CD"
} }
], ],
"VolumeDevice": "JVC AV Receiver", "VolumeDevice": "JVC AV Receiver",
@ -160,7 +160,7 @@
"DeviceSetupList": [ "DeviceSetupList": [
{ {
"DeviceName": "Vizio TV", "DeviceName": "Vizio TV",
"Input": "HDMI1" "Input": "Hdmi1"
}, },
{ {
"DeviceName": "Harman Kardon AV Receiver", "DeviceName": "Harman Kardon AV Receiver",
@ -185,7 +185,7 @@
}, },
{ {
"DeviceName": "Vizio TV", "DeviceName": "Vizio TV",
"Input": "HDMI1" "Input": "Hdmi1"
}, },
{ {
"DeviceName": "Harman Kardon AV Receiver", "DeviceName": "Harman Kardon AV Receiver",
@ -206,11 +206,11 @@
}, },
{ {
"DeviceName": "Vizio TV", "DeviceName": "Vizio TV",
"Input": "HDMI1" "Input": "Hdmi1"
}, },
{ {
"DeviceName": "Harman Kardon AV Receiver", "DeviceName": "Harman Kardon AV Receiver",
"Input": "DVD" "Input": "Dvd"
} }
], ],
"VolumeDevice": "Harman Kardon AV Receiver", "VolumeDevice": "Harman Kardon AV Receiver",
@ -227,7 +227,7 @@
}, },
{ {
"DeviceName": "Vizio TV", "DeviceName": "Vizio TV",
"Input": "HDMI1" "Input": "Hdmi1"
}, },
{ {
"DeviceName": "Harman Kardon AV Receiver", "DeviceName": "Harman Kardon AV Receiver",
@ -253,7 +253,7 @@
}, },
{ {
"DeviceName": "Westinghouse TV", "DeviceName": "Westinghouse TV",
"Input": "HDMI1" "Input": "Hdmi1"
} }
], ],
"VolumeDevice": "Westinghouse TV", "VolumeDevice": "Westinghouse TV",
@ -270,7 +270,7 @@
}, },
{ {
"DeviceName": "Westinghouse TV", "DeviceName": "Westinghouse TV",
"Input": "HDMI1" "Input": "Hdmi1"
} }
], ],
"VolumeDevice": "Westinghouse TV", "VolumeDevice": "Westinghouse TV",
@ -283,7 +283,7 @@
"DeviceSetupList": [ "DeviceSetupList": [
{ {
"DeviceName": "Westinghouse TV", "DeviceName": "Westinghouse TV",
"Input": "HDMI1" "Input": "Hdmi1"
}, },
{ {
"DeviceName": "Microsoft Xbox One", "DeviceName": "Microsoft Xbox One",

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

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": {
@ -39,4 +39,4 @@
"homebridge": "^0.4.50", "homebridge": "^0.4.50",
"request": "^2.88.0" "request": "^2.88.0"
} }
} }

View File

@ -9,6 +9,25 @@ let Characteristic: HAPNodeJS.Characteristic;
let Api: any; let Api: any;
let homebridge: any; let homebridge: any;
/**
* Enum describing remote key presses from homebridge.
*/
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,
}
export interface IControlUnitProps { export interface IControlUnitProps {
dataProvider: HarmonyDataProvider, dataProvider: HarmonyDataProvider,
displayName: string, displayName: string,
@ -51,19 +70,22 @@ 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.name = props.displayName;
this.displayName = props.displayName; this.displayName = props.displayName;
this.name = this.displayName;
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();
this.configureTvSpeakerService(); this.configureTvSpeakerService();
// this.configureAccessoryInformation(); // this.configureAccessoryInformation();
this.configureInputSourceService(); this.configureInputSourceService();
@ -108,10 +130,12 @@ export class ControlUnit implements IAccessory {
//@ts-ignore //@ts-ignore
.on("get", callbackify(this.onGetAccessoryActive)); .on("get", callbackify(this.onGetAccessoryActive));
//Set remote characteristics if is external
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
.on("set", callbackify(this.onSetActiveIdentifier)) .on("set", callbackify(this.onSetActiveIdentifier))
@ -135,7 +159,7 @@ export class ControlUnit implements IAccessory {
*/ */
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
} }
/** /**
@ -205,22 +229,6 @@ export class ControlUnit implements IAccessory {
} }
} }
/*********************
*
* 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')
}
/***************** /*****************
* *
* Input services * Input services
@ -266,8 +274,6 @@ export class ControlUnit implements IAccessory {
}); });
} }
/** /**
* Called by homebridge to gather services for this accessory. * Called by homebridge to gather services for this accessory.
*/ */

View File

@ -1,3 +1,7 @@
/**
* Interface to describe homebridge required elements.
*/
export interface IAccessory { export interface IAccessory {
/** /**
* Required by homebridge. * Required by homebridge.

View File

@ -1,7 +1,8 @@
import { Activity } from "../Models/Activity"; import { Activity } from "../Models/Activity";
import { DeviceSetupItem } from "../Models/DeviceSetupItem"; import { DeviceSetupItem } from "../Models/DeviceSetupItem";
import { threadId } from "worker_threads";
import { Input, Matrix, Output } from "../Models/Matrix"; import { Input, Matrix, Output } from "../Models/Matrix";
import { RemoteKey } from '../Accessories/ControlUnit';
import { sleep } from '../Util/Sleep';
let Characteristic: HAPNodeJS.Characteristic; let Characteristic: HAPNodeJS.Characteristic;
@ -19,22 +20,6 @@ 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,
@ -70,6 +55,9 @@ class HarmonyDataProvider {
this.connect(); this.connect();
} }
/**
* Power on all devices in an activity.
*/
public powerOn = async (controlUnitName: string, activity: Activity) => { public powerOn = async (controlUnitName: string, activity: Activity) => {
//Only power on if not alread on //Only power on if not alread on
let currentActivity = this.states[controlUnitName] ? this.states[controlUnitName]!.currentActivity : undefined; let currentActivity = this.states[controlUnitName] ? this.states[controlUnitName]!.currentActivity : undefined;
@ -78,6 +66,9 @@ class HarmonyDataProvider {
} }
} }
/**
* Power off all devices in an activity that aren't being used.
*/
public powerOff = async (controlUnitName: string) => { public powerOff = async (controlUnitName: string) => {
if (!this.states[controlUnitName]) { if (!this.states[controlUnitName]) {
return; return;
@ -99,6 +90,9 @@ class HarmonyDataProvider {
this.states[controlUnitName] = undefined; this.states[controlUnitName] = undefined;
} }
/**
* Start an activity
*/
public startActivity = async (controlUnitName: string, activity: Activity) => { public startActivity = async (controlUnitName: string, activity: Activity) => {
this.log(`Starting activity ${activity.displayName} for controlUnit: ${controlUnitName}`) this.log(`Starting activity ${activity.displayName} for controlUnit: ${controlUnitName}`)
let lastActivity: Activity | undefined = undefined; let lastActivity: Activity | undefined = undefined;
@ -148,8 +142,10 @@ class HarmonyDataProvider {
//Route hdmi //Route hdmi
if (matrixDevice.supportsCommand(inputCommandName) && matrixDevice.supportsCommand(outputCommandName)) { if (matrixDevice.supportsCommand(inputCommandName) && matrixDevice.supportsCommand(outputCommandName)) {
await this.sendCommand(matrixDevice.getCommand(outputCommandName));
await this.sendCommand(matrixDevice.getCommand(inputCommandName)); await this.sendCommand(matrixDevice.getCommand(inputCommandName));
await this.sendCommand(matrixDevice.getCommand(outputCommandName)); await this.sendCommand(matrixDevice.getCommand(outputCommandName));
await this.sendCommand(matrixDevice.getCommand(inputCommandName));
} }
} }
@ -192,6 +188,9 @@ class HarmonyDataProvider {
this.states[controlUnitName] = { currentActivity: activity }; this.states[controlUnitName] = { currentActivity: activity };
} }
/**
* Turn the volume up for the current running activity.
*/
public volumeUp = async (controlUnitName: string) => { public volumeUp = async (controlUnitName: string) => {
let volumeUpCommand: string = "Volume Up" let volumeUpCommand: string = "Volume Up"
if (this.states[controlUnitName]) { if (this.states[controlUnitName]) {
@ -202,6 +201,9 @@ class HarmonyDataProvider {
} }
} }
/**
* Volume down for current running activity.
*/
public volumeDown = async (controlUnitName: string) => { public volumeDown = async (controlUnitName: string) => {
let volumeDownCommand: string = "Volume Down" let volumeDownCommand: string = "Volume Down"
if (this.states[controlUnitName]) { if (this.states[controlUnitName]) {
@ -212,52 +214,50 @@ class HarmonyDataProvider {
} }
} }
/**
* Send key press for current activity.
*
* @param controlUnitName The name of the control unit to act on.
* @param key The key to send.
*/
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) {
//@ts-ignore
case RemoteKey.ARROW_UP: { case RemoteKey.ARROW_UP: {
commandName = "Direction Up"; commandName = "Direction Up";
break; break;
} }
//@ts-ignore
case RemoteKey.ARROW_DOWN: { case RemoteKey.ARROW_DOWN: {
commandName = "Direction Down"; commandName = "Direction Down";
break; break;
} }
//@ts-ignore
case RemoteKey.ARROW_LEFT: { case RemoteKey.ARROW_LEFT: {
commandName = "Direction Left"; commandName = "Direction Left";
break; break;
} }
//@ts-ignore
case RemoteKey.ARROW_RIGHT: { case RemoteKey.ARROW_RIGHT: {
commandName = "Direction Right"; commandName = "Direction Right";
break; break;
} }
//@ts-ignore
case RemoteKey.SELECT: { case RemoteKey.SELECT: {
commandName = "Select"; commandName = "Select";
break; break;
} }
//@ts-ignore
case RemoteKey.PLAY_PAUSE: { case RemoteKey.PLAY_PAUSE: {
commandName = "Pause"; commandName = "Pause";
break; break;
} }
//@ts-ignore
case RemoteKey.INFORMATION: { case RemoteKey.INFORMATION: {
commandName = "Menu"; commandName = "Menu";
break; break;
} }
//@ts-ignore
case RemoteKey.BACK: { case RemoteKey.BACK: {
commandName = "Back"; commandName = "Back";
break; break;
} }
//@ts-ignore
case RemoteKey.EXIT: { case RemoteKey.EXIT: {
commandName = "Back"; commandName = "Back";
break; break;
@ -270,6 +270,10 @@ class HarmonyDataProvider {
} }
} }
/**
* Return if a control unit is active
* @param controlUnitName
*/
public getIsActive(controlUnitName: string): Activity | undefined { public getIsActive(controlUnitName: string): Activity | undefined {
return this.states[controlUnitName] ? this.states[controlUnitName]!.currentActivity : undefined; return this.states[controlUnitName] ? this.states[controlUnitName]!.currentActivity : undefined;
} }
@ -318,6 +322,9 @@ class HarmonyDataProvider {
}, 1000); }, 1000);
} }
/**
* Power off a device (Power toggle if no power off).
*/
private powerOffDevice = async (device: IDevice) => { private powerOffDevice = async (device: IDevice) => {
let powerOffCommand: string = "Power Off"; let powerOffCommand: string = "Power Off";
let powerToggleCommand: string = "Power Toggle"; let powerToggleCommand: string = "Power Toggle";
@ -330,6 +337,9 @@ class HarmonyDataProvider {
} }
} }
/**
* Power on a device (Power toggle if no power on).
*/
private powerOnDevice = async (device: IDevice) => { private powerOnDevice = async (device: IDevice) => {
let powerOnCommand: string = "Power On"; let powerOnCommand: string = "Power On";
let powerToggleCommand: string = "Power Toggle"; let powerToggleCommand: string = "Power Toggle";
@ -342,10 +352,19 @@ class HarmonyDataProvider {
} }
} }
/**
* Get the IDevice by name.
* @param deviceName The device to retrieve.
*/
private getDeviceFromName(deviceName: string): IDevice { private getDeviceFromName(deviceName: string): IDevice {
return this.devices[deviceName]; 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> { private sanitizeDeviceList(devicesToTurnOn: Array<IDevice>, controlUnitName: string): Array<IDevice> {
for (let controlUnitKey in this.states) { for (let controlUnitKey in this.states) {
//Skip self //Skip self
@ -368,10 +387,17 @@ class HarmonyDataProvider {
return devicesToTurnOn; return devicesToTurnOn;
} }
/**
* Send a command to the harmony hub.
* @param command The command to send.
*/
private sendCommand = async (command: string) => { private sendCommand = async (command: string) => {
try { try {
//Execute command
let response = await this.harmony.sendCommand(JSON.stringify(command)); let response = await this.harmony.sendCommand(JSON.stringify(command));
// this.log(`Sent command: ${JSON.stringify(command)} response: ${JSON.stringify(response)}`);
//Sleep
await sleep(800);
} catch (err) { } catch (err) {
this.log(`ERROR - error sending command to harmony: ${err}`); this.log(`ERROR - error sending command to harmony: ${err}`);
} }

View File

@ -4,6 +4,9 @@ export interface IDeviceSetupItemProps {
input: string input: string
} }
/**
* Data model to hold device setup items.
*/
export class DeviceSetupItem { export class DeviceSetupItem {
private _deviceId: string = ""; private _deviceId: string = "";
private _input: string = ""; private _input: string = "";

View File

@ -14,6 +14,9 @@ export interface Output {
outputDevice: string, outputDevice: string,
} }
/**
* Data model to hold matrix information.
*/
export class Matrix { export class Matrix {
private _inputs: Array<Input> = []; private _inputs: Array<Input> = [];
private _outputs: Array<Output> = []; private _outputs: Array<Output> = [];

View File

@ -1,5 +1,8 @@
/**
* Helper function to convert callbacks into promises
* @param func
*/
export default function callbackify(func: (...args: any[]) => Promise<any>): Function { export default function callbackify(func: (...args: any[]) => Promise<any>): Function {
return (...args: any[]) => { return (...args: any[]) => {
const onlyArgs: any[] = []; const onlyArgs: any[] = [];

3
src/Util/Sleep.ts Normal file
View File

@ -0,0 +1,3 @@
export function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}

View File

@ -7,6 +7,10 @@ import HarmonyDataProvider from "./DataProviders/HarmonyDataProvider";
let Accessory: any; let Accessory: any;
let Homebridge: any; let Homebridge: any;
/**
* Main entry.
* @param homebridge
*/
export default function (homebridge: any) { export default function (homebridge: any) {
Homebridge = homebridge; Homebridge = homebridge;
Accessory = homebridge.platformAccessory; Accessory = homebridge.platformAccessory;
@ -22,7 +26,8 @@ class HarmonyMatrixPlatform {
log: any = {}; log: any = {};
config: any = {}; config: any = {};
api: any; api: any;
externalAccessories: Array<any> = []; 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;
@ -30,12 +35,20 @@ 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
* Happens after constructor
*/
didFinishLaunching() { didFinishLaunching() {
this.log(`Publishing external accessories`); this.log(`Publishing external accessories`);
this.externalAccessories.forEach((accessory: ControlUnit) => { //This is required in order to have multiple tv remotes on one platform
this.controlUnits.forEach((accessory: ControlUnit) => {
this.api.publishExternalAccessories("HarmonyMatrixPlatform", [accessory.platformAccessory]); this.api.publishExternalAccessories("HarmonyMatrixPlatform", [accessory.platformAccessory]);
}) })
@ -88,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
@ -96,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"];
@ -120,33 +133,30 @@ 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"]}'`);
}); });
// let accessory = new Accessory(configControlUnit["DisplayName"],
// Homebridge.hap.uuid.generate(configControlUnit["DisplayName"], Homebridge.hap.Accessory.Categories.TELEVISION));
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,
}); });
//@ts-ignore //@ts-ignore
let accessory = controlUnit as homebridge.platformAccessory; let accessory = controlUnit as homebridge.platformAccessory;
//@ts-ignore
//Add control unit //Add control unit
controlUnits.push(accessory); this.controlUnits.push(accessory);
this.log(`INFO - Added ControlUnit`); this.log(`INFO - Added ControlUnit`);
}); });
this.externalAccessories = controlUnits; callback(this.controlUnits);
callback(controlUnits);
} }
} }

View File

@ -5,6 +5,7 @@
"declaration": true, "declaration": true,
"outDir": "./bin", "outDir": "./bin",
"strict": true, "strict": true,
"sourceMap": true,
}, },
"include": [ "include": [
"src" "src"