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": {
|
"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",
|
||||||
|
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 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,
|
||||||
@ -16,6 +35,7 @@ export interface IControlUnitProps {
|
|||||||
api: any,
|
api: any,
|
||||||
log: any,
|
log: any,
|
||||||
homebridge: any,
|
homebridge: any,
|
||||||
|
isExternal: boolean,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,6 +48,7 @@ export class ControlUnit implements IAccessory {
|
|||||||
//fields
|
//fields
|
||||||
private log: any = {};
|
private log: any = {};
|
||||||
private displayName: string = "";
|
private displayName: string = "";
|
||||||
|
private isExternal: boolean = false;
|
||||||
|
|
||||||
//Service fields
|
//Service fields
|
||||||
private televisionService: HAPNodeJS.Service | undefined;
|
private televisionService: HAPNodeJS.Service | undefined;
|
||||||
@ -51,19 +72,23 @@ export class ControlUnit implements IAccessory {
|
|||||||
Api = props.api;
|
Api = props.api;
|
||||||
Service = props.api.hap.Service;
|
Service = props.api.hap.Service;
|
||||||
Characteristic = props.api.hap.Characteristic;
|
Characteristic = props.api.hap.Characteristic;
|
||||||
this.displayName = props.displayName;
|
this.name = props.displayName;
|
||||||
this.name = this.displayName;
|
this.displayName = props.isExternal ? `${props.displayName}-Remote` : props.displayName;
|
||||||
|
this.isExternal = props.isExternal;
|
||||||
|
|
||||||
this.activities = props.activities;
|
this.activities = props.activities;
|
||||||
|
|
||||||
this.dataProvider = props.dataProvider;
|
this.dataProvider = props.dataProvider;
|
||||||
homebridge = props.homebridge;
|
homebridge = props.homebridge;
|
||||||
|
|
||||||
this.platformAccessory = new homebridge.platformAccessory(this.name, this.generateUUID(), homebridge.hap.Accessory.Categories.TELEVISION);
|
this.platformAccessory = new homebridge.platformAccessory(this.displayName, this.generateUUID(), homebridge.hap.Accessory.Categories.TELEVISION);
|
||||||
|
|
||||||
//Configure services
|
//Configure services
|
||||||
this.configureTvService();
|
this.configureTvService();
|
||||||
|
|
||||||
this.configureTvSpeakerService();
|
this.configureTvSpeakerService();
|
||||||
|
|
||||||
|
|
||||||
// this.configureAccessoryInformation();
|
// this.configureAccessoryInformation();
|
||||||
this.configureInputSourceService();
|
this.configureInputSourceService();
|
||||||
|
|
||||||
@ -108,9 +133,12 @@ export class ControlUnit implements IAccessory {
|
|||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
.on("get", callbackify(this.onGetAccessoryActive));
|
.on("get", callbackify(this.onGetAccessoryActive));
|
||||||
|
|
||||||
this.televisionService.getCharacteristic(Characteristic.RemoteKey)
|
//Set remote characteristics if is external
|
||||||
//@ts-ignore
|
if (this.isExternal) {
|
||||||
.on("set", callbackify(this.onSetRemoteKey));
|
this.televisionService.getCharacteristic(Characteristic.RemoteKey)
|
||||||
|
//@ts-ignore
|
||||||
|
.on("set", callbackify(this.onSetRemoteKey));
|
||||||
|
}
|
||||||
|
|
||||||
this.televisionService.getCharacteristic(Characteristic.ActiveIdentifier)
|
this.televisionService.getCharacteristic(Characteristic.ActiveIdentifier)
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
@ -123,10 +151,12 @@ 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) => {
|
||||||
switch (value) {
|
if (!this.isExternal) {
|
||||||
case 0: this.dataProvider.powerOff(this.name); break;
|
switch (value) {
|
||||||
//Turn on with first activity
|
case 0: this.dataProvider.powerOff(this.name); break;
|
||||||
case 1: this.dataProvider.powerOn(this.name, this.activities[0]); break;
|
//Turn on with first activity
|
||||||
|
case 1: this.dataProvider.powerOn(this.name, this.activities[0]); break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,21 +165,33 @@ 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() ? 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) => {
|
||||||
this.dataProvider.sendKeyPress(this.name, key);
|
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
|
* Event handler for SET active identifier characteristic
|
||||||
*/
|
*/
|
||||||
private onSetActiveIdentifier = async (identifier: any) => {
|
private onSetActiveIdentifier = async (identifier: any) => {
|
||||||
this.dataProvider.startActivity(this.name, this.activities[identifier]);
|
if (!this.isExternal) {
|
||||||
|
this.dataProvider.startActivity(this.name, this.activities[identifier]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -199,9 +241,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) => {
|
||||||
switch (value) {
|
if (this.isExternal) {
|
||||||
case 0: this.dataProvider.volumeUp(this.name); break;
|
switch (value) {
|
||||||
case 1: this.dataProvider.volumeDown(this.name); break;
|
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.
|
* Called by homebridge to gather services for this accessory.
|
||||||
*/
|
*/
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* Interface to describe homebridge required elements.
|
||||||
|
*/
|
||||||
export interface IAccessory {
|
export interface IAccessory {
|
||||||
/**
|
/**
|
||||||
* Required by homebridge.
|
* Required by homebridge.
|
||||||
|
@ -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}`);
|
||||||
}
|
}
|
||||||
|
@ -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 = "";
|
||||||
|
@ -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> = [];
|
||||||
|
@ -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
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 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;
|
||||||
@ -23,6 +27,7 @@ class HarmonyMatrixPlatform {
|
|||||||
config: any = {};
|
config: any = {};
|
||||||
api: any;
|
api: any;
|
||||||
externalAccessories: Array<any> = [];
|
externalAccessories: Array<any> = [];
|
||||||
|
dataProvider: HarmonyDataProvider | null;
|
||||||
|
|
||||||
constructor(log: any, config: any, api: any) {
|
constructor(log: any, config: any, api: any) {
|
||||||
this.log = log;
|
this.log = log;
|
||||||
@ -30,11 +35,19 @@ 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 is required in order to have multiple tv remotes on one platform
|
||||||
this.externalAccessories.forEach((accessory: ControlUnit) => {
|
this.externalAccessories.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
|
||||||
@ -120,33 +133,44 @@ 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,
|
||||||
|
isExternal: false
|
||||||
|
});
|
||||||
|
|
||||||
|
let controlUnitExternal: ControlUnit = new ControlUnit({
|
||||||
|
dataProvider: this.dataProvider!,
|
||||||
|
displayName: `${configControlUnit["DisplayName"]}`,
|
||||||
|
api: this.api,
|
||||||
|
log: this.log,
|
||||||
|
activities: activities,
|
||||||
|
homebridge: Homebridge,
|
||||||
|
isExternal: true
|
||||||
});
|
});
|
||||||
|
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
let accessory = controlUnit as homebridge.platformAccessory;
|
let accessory = controlUnit as homebridge.platformAccessory;
|
||||||
|
//@ts-ignore
|
||||||
|
let externalAccessory = controlUnitExternal as homebridge.platformAccessory;
|
||||||
|
|
||||||
//Add control unit
|
//Add control unit
|
||||||
controlUnits.push(accessory);
|
controlUnits.push(accessory);
|
||||||
|
//Add to list of remotes
|
||||||
|
this.externalAccessories.push(externalAccessory);
|
||||||
|
|
||||||
this.log(`INFO - Added ControlUnit`);
|
this.log(`INFO - Added ControlUnit`);
|
||||||
});
|
});
|
||||||
this.externalAccessories = controlUnits;
|
|
||||||
callback(controlUnits);
|
callback(controlUnits);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,6 +5,7 @@
|
|||||||
"declaration": true,
|
"declaration": true,
|
||||||
"outDir": "./bin",
|
"outDir": "./bin",
|
||||||
"strict": true,
|
"strict": true,
|
||||||
|
"sourceMap": true,
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"src"
|
"src"
|
||||||
|
Reference in New Issue
Block a user