Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
f682c0e380 | |||
14312908bf | |||
152d73e9f9 | |||
727c8ceba7 | |||
39f4a7c1bc | |||
73cba09edb | |||
9b48614dd1 | |||
04024d565d | |||
7638644935 | |||
f0eb57e4dc | |||
0ea4188487 | |||
8bb65b5b3c |
16
.vscode/launch.json
vendored
Normal file
16
.vscode/launch.json
vendored
Normal 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
17
.vscode/tasks.json
vendored
Normal 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 ."
|
||||
}
|
||||
]
|
||||
}
|
36
config.json
36
config.json
@ -1,7 +1,7 @@
|
||||
{
|
||||
"bridge": {
|
||||
"name": "Homebridge",
|
||||
"username": "CC:22:3D:E3:CE:42",
|
||||
"username": "CC:22:3D:E3:CE:74",
|
||||
"port": 51826,
|
||||
"pin": "031-45-154"
|
||||
},
|
||||
@ -58,11 +58,11 @@
|
||||
"DeviceSetupList": [
|
||||
{
|
||||
"DeviceName": "LG TV",
|
||||
"Input": "HDMI1"
|
||||
"Input": "Hdmi1"
|
||||
},
|
||||
{
|
||||
"DeviceName": "JVC AV Receiver",
|
||||
"Input": "DVD"
|
||||
"Input": "Dvd"
|
||||
},
|
||||
{
|
||||
"DeviceName": "Chromecast",
|
||||
@ -83,11 +83,11 @@
|
||||
},
|
||||
{
|
||||
"DeviceName": "LG TV",
|
||||
"Input": "HDMI1"
|
||||
"Input": "Hdmi1"
|
||||
},
|
||||
{
|
||||
"DeviceName": "JVC AV Receiver",
|
||||
"Input": "DVD"
|
||||
"Input": "Dvd"
|
||||
}
|
||||
],
|
||||
"VolumeDevice": "JVC AV Receiver",
|
||||
@ -104,11 +104,11 @@
|
||||
},
|
||||
{
|
||||
"DeviceName": "LG TV",
|
||||
"Input": "HDMI1"
|
||||
"Input": "Hdmi1"
|
||||
},
|
||||
{
|
||||
"DeviceName": "JVC AV Receiver",
|
||||
"Input": "DVD"
|
||||
"Input": "Dvd"
|
||||
}
|
||||
],
|
||||
"VolumeDevice": "JVC AV Receiver",
|
||||
@ -125,11 +125,11 @@
|
||||
},
|
||||
{
|
||||
"DeviceName": "LG TV",
|
||||
"Input": "HDMI1"
|
||||
"Input": "Hdmi1"
|
||||
},
|
||||
{
|
||||
"DeviceName": "JVC AV Receiver",
|
||||
"Input": "DVD"
|
||||
"Input": "Dvd"
|
||||
}
|
||||
],
|
||||
"VolumeDevice": "JVC AV Receiver",
|
||||
@ -142,7 +142,7 @@
|
||||
"DeviceSetupList": [
|
||||
{
|
||||
"DeviceName": "JVC AV Receiver",
|
||||
"Input": "DVD"
|
||||
"Input": "CD"
|
||||
}
|
||||
],
|
||||
"VolumeDevice": "JVC AV Receiver",
|
||||
@ -160,7 +160,7 @@
|
||||
"DeviceSetupList": [
|
||||
{
|
||||
"DeviceName": "Vizio TV",
|
||||
"Input": "HDMI1"
|
||||
"Input": "Hdmi1"
|
||||
},
|
||||
{
|
||||
"DeviceName": "Harman Kardon AV Receiver",
|
||||
@ -185,7 +185,7 @@
|
||||
},
|
||||
{
|
||||
"DeviceName": "Vizio TV",
|
||||
"Input": "HDMI1"
|
||||
"Input": "Hdmi1"
|
||||
},
|
||||
{
|
||||
"DeviceName": "Harman Kardon AV Receiver",
|
||||
@ -206,11 +206,11 @@
|
||||
},
|
||||
{
|
||||
"DeviceName": "Vizio TV",
|
||||
"Input": "HDMI1"
|
||||
"Input": "Hdmi1"
|
||||
},
|
||||
{
|
||||
"DeviceName": "Harman Kardon AV Receiver",
|
||||
"Input": "DVD"
|
||||
"Input": "Dvd"
|
||||
}
|
||||
],
|
||||
"VolumeDevice": "Harman Kardon AV Receiver",
|
||||
@ -227,7 +227,7 @@
|
||||
},
|
||||
{
|
||||
"DeviceName": "Vizio TV",
|
||||
"Input": "HDMI1"
|
||||
"Input": "Hdmi1"
|
||||
},
|
||||
{
|
||||
"DeviceName": "Harman Kardon AV Receiver",
|
||||
@ -253,7 +253,7 @@
|
||||
},
|
||||
{
|
||||
"DeviceName": "Westinghouse TV",
|
||||
"Input": "HDMI1"
|
||||
"Input": "Hdmi1"
|
||||
}
|
||||
],
|
||||
"VolumeDevice": "Westinghouse TV",
|
||||
@ -270,7 +270,7 @@
|
||||
},
|
||||
{
|
||||
"DeviceName": "Westinghouse TV",
|
||||
"Input": "HDMI1"
|
||||
"Input": "Hdmi1"
|
||||
}
|
||||
],
|
||||
"VolumeDevice": "Westinghouse TV",
|
||||
@ -283,7 +283,7 @@
|
||||
"DeviceSetupList": [
|
||||
{
|
||||
"DeviceName": "Westinghouse TV",
|
||||
"Input": "HDMI1"
|
||||
"Input": "Hdmi1"
|
||||
},
|
||||
{
|
||||
"DeviceName": "Microsoft Xbox One",
|
||||
|
21
deploy.sh
Executable file
21
deploy.sh
Executable file
@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
remote_user="bmw"
|
||||
remote_server="192.168.1.31"
|
||||
deploy_location="/home/bmw/homebridge-harmony-control"
|
||||
homebridge_location="/var/lib/homebridge/"
|
||||
|
||||
#copy files to remote machine
|
||||
scp -r bin $remote_user@$remote_server:$deploy_location
|
||||
scp -r src $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
|
@ -9,6 +9,25 @@ let Characteristic: HAPNodeJS.Characteristic;
|
||||
let Api: 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 {
|
||||
dataProvider: HarmonyDataProvider,
|
||||
displayName: string,
|
||||
@ -16,6 +35,7 @@ export interface IControlUnitProps {
|
||||
api: any,
|
||||
log: any,
|
||||
homebridge: any,
|
||||
isExternal: boolean,
|
||||
}
|
||||
|
||||
/**
|
||||
@ -28,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;
|
||||
@ -51,19 +72,23 @@ 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;
|
||||
|
||||
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();
|
||||
|
||||
this.configureTvSpeakerService();
|
||||
|
||||
|
||||
// this.configureAccessoryInformation();
|
||||
this.configureInputSourceService();
|
||||
|
||||
@ -108,9 +133,12 @@ export class ControlUnit implements IAccessory {
|
||||
//@ts-ignore
|
||||
.on("get", callbackify(this.onGetAccessoryActive));
|
||||
|
||||
//Set remote characteristics if is external
|
||||
if (this.isExternal) {
|
||||
this.televisionService.getCharacteristic(Characteristic.RemoteKey)
|
||||
//@ts-ignore
|
||||
.on("set", callbackify(this.onSetRemoteKey));
|
||||
}
|
||||
|
||||
this.televisionService.getCharacteristic(Characteristic.ActiveIdentifier)
|
||||
//@ts-ignore
|
||||
@ -123,34 +151,48 @@ export class ControlUnit implements IAccessory {
|
||||
* Event handler for SET active characteristic
|
||||
*/
|
||||
private onSetAccessoryActive = async (value: any) => {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Event handler for GET active characteristic
|
||||
*/
|
||||
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
|
||||
}
|
||||
|
||||
/**
|
||||
* Event handler for SET remote key
|
||||
*/
|
||||
private onSetRemoteKey = async (key: any) => {
|
||||
if (this.isExternal) {
|
||||
//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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Event handler for SET active identifier characteristic
|
||||
*/
|
||||
private onSetActiveIdentifier = async (identifier: any) => {
|
||||
if (!this.isExternal) {
|
||||
this.dataProvider.startActivity(this.name, this.activities[identifier]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Event handler for GET active identifier characteristic
|
||||
@ -199,11 +241,13 @@ export class ControlUnit implements IAccessory {
|
||||
* Event handler for SET volume characteristic
|
||||
*/
|
||||
private onSetVolumeSelector = async (value: any) => {
|
||||
if (this.isExternal) {
|
||||
switch (value) {
|
||||
case 0: this.dataProvider.volumeUp(this.name); break;
|
||||
case 1: this.dataProvider.volumeDown(this.name); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*********************
|
||||
*
|
||||
@ -266,8 +310,6 @@ export class ControlUnit implements IAccessory {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Called by homebridge to gather services for this accessory.
|
||||
*/
|
||||
|
@ -1,3 +1,7 @@
|
||||
|
||||
/**
|
||||
* Interface to describe homebridge required elements.
|
||||
*/
|
||||
export interface IAccessory {
|
||||
/**
|
||||
* Required by homebridge.
|
||||
|
@ -1,7 +1,8 @@
|
||||
import { Activity } from "../Models/Activity";
|
||||
import { DeviceSetupItem } from "../Models/DeviceSetupItem";
|
||||
import { threadId } from "worker_threads";
|
||||
import { Input, Matrix, Output } from "../Models/Matrix";
|
||||
import { RemoteKey } from '../Accessories/ControlUnit';
|
||||
import { sleep } from '../Util/Sleep';
|
||||
|
||||
let Characteristic: HAPNodeJS.Characteristic;
|
||||
|
||||
@ -19,22 +20,6 @@ interface IActivityState {
|
||||
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 {
|
||||
hubAddress: string,
|
||||
log: any,
|
||||
@ -70,6 +55,9 @@ class HarmonyDataProvider {
|
||||
this.connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Power on all devices in an activity.
|
||||
*/
|
||||
public powerOn = async (controlUnitName: string, activity: Activity) => {
|
||||
//Only power on if not alread on
|
||||
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) => {
|
||||
if (!this.states[controlUnitName]) {
|
||||
return;
|
||||
@ -99,6 +90,9 @@ class HarmonyDataProvider {
|
||||
this.states[controlUnitName] = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start an activity
|
||||
*/
|
||||
public startActivity = async (controlUnitName: string, activity: Activity) => {
|
||||
this.log(`Starting activity ${activity.displayName} for controlUnit: ${controlUnitName}`)
|
||||
let lastActivity: Activity | undefined = undefined;
|
||||
@ -148,8 +142,10 @@ class HarmonyDataProvider {
|
||||
|
||||
//Route hdmi
|
||||
if (matrixDevice.supportsCommand(inputCommandName) && matrixDevice.supportsCommand(outputCommandName)) {
|
||||
await this.sendCommand(matrixDevice.getCommand(outputCommandName));
|
||||
await this.sendCommand(matrixDevice.getCommand(inputCommandName));
|
||||
await this.sendCommand(matrixDevice.getCommand(outputCommandName));
|
||||
await this.sendCommand(matrixDevice.getCommand(inputCommandName));
|
||||
}
|
||||
}
|
||||
|
||||
@ -192,6 +188,9 @@ class HarmonyDataProvider {
|
||||
this.states[controlUnitName] = { currentActivity: activity };
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn the volume up for the current running activity.
|
||||
*/
|
||||
public volumeUp = async (controlUnitName: string) => {
|
||||
let volumeUpCommand: string = "Volume Up"
|
||||
if (this.states[controlUnitName]) {
|
||||
@ -202,6 +201,9 @@ class HarmonyDataProvider {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Volume down for current running activity.
|
||||
*/
|
||||
public volumeDown = async (controlUnitName: string) => {
|
||||
let volumeDownCommand: string = "Volume Down"
|
||||
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) => {
|
||||
if (this.states[controlUnitName]) {
|
||||
let commandName: string = "";
|
||||
|
||||
let device: IDevice = this.getDeviceFromName(this.states[controlUnitName]!.currentActivity.controlDeviceId);
|
||||
switch (key) {
|
||||
//@ts-ignore
|
||||
case RemoteKey.ARROW_UP: {
|
||||
commandName = "Direction Up";
|
||||
break;
|
||||
}
|
||||
//@ts-ignore
|
||||
case RemoteKey.ARROW_DOWN: {
|
||||
commandName = "Direction Down";
|
||||
break;
|
||||
}
|
||||
//@ts-ignore
|
||||
case RemoteKey.ARROW_LEFT: {
|
||||
commandName = "Direction Left";
|
||||
break;
|
||||
}
|
||||
//@ts-ignore
|
||||
case RemoteKey.ARROW_RIGHT: {
|
||||
commandName = "Direction Right";
|
||||
break;
|
||||
}
|
||||
//@ts-ignore
|
||||
case RemoteKey.SELECT: {
|
||||
commandName = "Select";
|
||||
break;
|
||||
}
|
||||
//@ts-ignore
|
||||
case RemoteKey.PLAY_PAUSE: {
|
||||
commandName = "Pause";
|
||||
break;
|
||||
}
|
||||
//@ts-ignore
|
||||
case RemoteKey.INFORMATION: {
|
||||
commandName = "Menu";
|
||||
break;
|
||||
}
|
||||
//@ts-ignore
|
||||
case RemoteKey.BACK: {
|
||||
commandName = "Back";
|
||||
break;
|
||||
}
|
||||
//@ts-ignore
|
||||
case RemoteKey.EXIT: {
|
||||
commandName = "Back";
|
||||
break;
|
||||
@ -270,6 +270,10 @@ class HarmonyDataProvider {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if a control unit is active
|
||||
* @param controlUnitName
|
||||
*/
|
||||
public getIsActive(controlUnitName: string): Activity | undefined {
|
||||
return this.states[controlUnitName] ? this.states[controlUnitName]!.currentActivity : undefined;
|
||||
}
|
||||
@ -318,6 +322,9 @@ class HarmonyDataProvider {
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Power off a device (Power toggle if no power off).
|
||||
*/
|
||||
private powerOffDevice = async (device: IDevice) => {
|
||||
let powerOffCommand: string = "Power Off";
|
||||
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) => {
|
||||
let powerOnCommand: string = "Power On";
|
||||
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 {
|
||||
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
|
||||
@ -368,10 +387,17 @@ class HarmonyDataProvider {
|
||||
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));
|
||||
// this.log(`Sent command: ${JSON.stringify(command)} response: ${JSON.stringify(response)}`);
|
||||
|
||||
//Sleep
|
||||
await sleep(800);
|
||||
} catch (err) {
|
||||
this.log(`ERROR - error sending command to harmony: ${err}`);
|
||||
}
|
||||
|
@ -4,6 +4,9 @@ export interface IDeviceSetupItemProps {
|
||||
input: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Data model to hold device setup items.
|
||||
*/
|
||||
export class DeviceSetupItem {
|
||||
private _deviceId: string = "";
|
||||
private _input: string = "";
|
||||
|
@ -14,6 +14,9 @@ export interface Output {
|
||||
outputDevice: string,
|
||||
}
|
||||
|
||||
/**
|
||||
* Data model to hold matrix information.
|
||||
*/
|
||||
export class Matrix {
|
||||
private _inputs: Array<Input> = [];
|
||||
private _outputs: Array<Output> = [];
|
||||
|
@ -1,5 +1,8 @@
|
||||
|
||||
|
||||
/**
|
||||
* Helper function to convert callbacks into promises
|
||||
* @param func
|
||||
*/
|
||||
export default function callbackify(func: (...args: any[]) => Promise<any>): Function {
|
||||
return (...args: any[]) => {
|
||||
const onlyArgs: any[] = [];
|
||||
|
3
src/Util/Sleep.ts
Normal file
3
src/Util/Sleep.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export function sleep(ms: number) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
40
src/index.ts
40
src/index.ts
@ -7,6 +7,10 @@ import HarmonyDataProvider from "./DataProviders/HarmonyDataProvider";
|
||||
let Accessory: any;
|
||||
let Homebridge: any;
|
||||
|
||||
/**
|
||||
* Main entry.
|
||||
* @param homebridge
|
||||
*/
|
||||
export default function (homebridge: any) {
|
||||
Homebridge = homebridge;
|
||||
Accessory = homebridge.platformAccessory;
|
||||
@ -23,6 +27,7 @@ class HarmonyMatrixPlatform {
|
||||
config: any = {};
|
||||
api: any;
|
||||
externalAccessories: Array<any> = [];
|
||||
dataProvider: HarmonyDataProvider | null;
|
||||
|
||||
constructor(log: any, config: any, api: any) {
|
||||
this.log = log;
|
||||
@ -30,11 +35,19 @@ class HarmonyMatrixPlatform {
|
||||
this.api = api;
|
||||
this.log('INFO - Registering Harmony Matrix Platform');
|
||||
this.api.on('didFinishLaunching', this.didFinishLaunching.bind(this));
|
||||
|
||||
this.dataProvider = null;
|
||||
this.log("This is new");
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for didFinishLaunching
|
||||
* Happens after constructor
|
||||
*/
|
||||
didFinishLaunching() {
|
||||
this.log(`Publishing external accessories`);
|
||||
|
||||
//This is required in order to have multiple tv remotes on one platform
|
||||
this.externalAccessories.forEach((accessory: ControlUnit) => {
|
||||
this.api.publishExternalAccessories("HarmonyMatrixPlatform", [accessory.platformAccessory]);
|
||||
})
|
||||
@ -88,7 +101,7 @@ class HarmonyMatrixPlatform {
|
||||
});
|
||||
|
||||
//construct data provider
|
||||
let dataProvider = new HarmonyDataProvider({
|
||||
this.dataProvider = new HarmonyDataProvider({
|
||||
hubAddress: hubIp,
|
||||
matrix: matrix,
|
||||
log: this.log
|
||||
@ -120,33 +133,44 @@ class HarmonyMatrixPlatform {
|
||||
controlDeviceId: configActivity["ControlDevice"],
|
||||
outputDeviceId: configActivity["OutputDevice"],
|
||||
displayName: configActivity["DisplayName"],
|
||||
useMatrix: configActivity["UseMatrix"],
|
||||
useMatrix: configActivity["UseMatrix"] === "true" ? true : false,
|
||||
deviceList: devices
|
||||
}));
|
||||
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({
|
||||
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"]}`,
|
||||
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);
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
"declaration": true,
|
||||
"outDir": "./bin",
|
||||
"strict": true,
|
||||
"sourceMap": true,
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
|
Reference in New Issue
Block a user