Inputs now appearing on home kit

This commit is contained in:
watsonb8 2019-06-15 00:40:09 -04:00
parent 39bf619b3a
commit 0ff8ce8622
2 changed files with 342 additions and 242 deletions

View File

@ -1,271 +1,300 @@
{ {
"platform": "HarmonyHubMatrix", "bridge": {
"ControlUnits": [ "name": "Homebridge",
"username": "CC:22:3D:E3:CE:42",
"port": 51826,
"pin": "031-45-154"
},
"platforms": [
{ {
"DisplayName": "Living Room", "platform": "websocket",
"Activities": [ "name": "websocket",
{ "port": 4050
"DisplayName": "Play Xbox One",
"DeviceSetupList": [
{
"DeviceName": "Microsoft Xbox One",
"Input": []
},
{
"DeviceName": "LG TV",
"Input": "HDMI1"
},
{
"DeviceName": "JVC AV Receiver",
"Input": "DVD"
}
],
"VolumeDevice": "JVC AV Receiver",
"ControlDevice": "Microsoft Xbox One",
"OutputDevice": "LG TV",
"UseMatrix": "true"
},
{
"DisplayName": "Play Xbox One",
"DeviceSetupList": [
{
"DeviceName": "Microsoft Xbox One",
"Input": []
},
{
"DeviceName": "LG TV",
"Input": "HDMI1"
},
{
"DeviceName": "JVC AV Receiver",
"Input": "DVD"
}
],
"VolumeDevice": "JVC AV Receiver",
"ControlDevice": "Microsoft Xbox One",
"OutputDevice": "LG TV",
"UseMatrix": "true"
},
{
"DisplayName": "Play PS4",
"DeviceSetupList": [
{
"DeviceName": "Sony PS4",
"Input": []
},
{
"DeviceName": [],
"Input": "HDMI1"
},
{
"DeviceName": [],
"Input": "DVD"
}
],
"VolumeDevice": "JVC AV Receiver",
"ControlDevice": "Sony PS4",
"OutputDevice": "LG TV",
"UseMatrix": "true"
},
{
"DisplayName": "Chromecast",
"DeviceSetupList": [
{
"DeviceName": "LG TV",
"Input": "HDMI1"
},
{
"DeviceName": "JVC AV Receiver",
"Input": "DVD"
},
{
"DeviceName": "Chromecast",
"Input": []
}
],
"VolumeDevice": "JVC AV Receiver",
"ControlDevice": "Chromecast",
"OutputDevice": "LG TV",
"UseMatrix": "true"
},
{
"DisplayName": "Apple TV",
"DeviceSetupList": [
{
"DeviceName": "Apple TV Gen 4",
"Input": []
},
{
"DeviceName": "LG TV",
"Input": "HDMI1"
},
{
"DeviceName": "JVC AV Receiver",
"Input": "DVD"
}
],
"VolumeDevice": "JVC AV Receiver",
"ControlDevice": "Apple TV Gen 4",
"OutputDevice": "LG TV",
"UseMatrix": "true"
},
{
"DisplayName": "Listen to Music",
"DeviceSetupList": [
{
"DeviceName": "JVC AV Receiver",
"Input": "DVD"
}
],
"VolumeDevice": "JVC AV Receiver",
"ControlDevice": [],
"OutputDevice": [],
"UseMatrix": "false"
}
]
}, },
{ {
"DisplayName": "Bedroom", "platform": "HarmonyHubMatrix",
"Activities": [ "Matrix": {
"DeviceName": "Gefen AV Switch",
"Inputs": [
{
"InputNumber": "1",
"InputDevice": "Microsoft Xbox One"
},
{
"InputNumber": "5",
"InputDevice": "Apple TV Gen 4"
},
{
"InputNumber": "3",
"InputDevice": "Chromecast"
},
{
"InputNumber": "2",
"InputDevice": "Sony PS4"
}
],
"Outputs": [
{
"OutputLetter": "B",
"OutputDevice": "LG TV"
},
{
"OutputLetter": "C",
"OutputDevice": "Vizio TV"
},
{
"OutputLetter": "D",
"OutputDevice": "Westinghouse TV"
}
]
},
"ControlUnits": [
{ {
"DisplayName": "Play Xbox One", "DisplayName": "Living Room",
"DeviceSetupList": [ "Activities": [
{ {
"Device": "Microsoft Xbox One", "DisplayName": "Play Xbox One",
"Input": [] "DeviceSetupList": [
{
"DeviceName": "Microsoft Xbox One",
"Input": []
},
{
"DeviceName": "LG TV",
"Input": "HDMI1"
},
{
"DeviceName": "JVC AV Receiver",
"Input": "DVD"
}
],
"VolumeDevice": "JVC AV Receiver",
"ControlDevice": "Microsoft Xbox One",
"OutputDevice": "LG TV",
"UseMatrix": "true"
}, },
{ {
"Device": "Vizio TV", "DisplayName": "Play PS4",
"Input": "HDMI1" "DeviceSetupList": [
{
"DeviceName": "Sony PS4",
"Input": []
},
{
"DeviceName": [],
"Input": "HDMI1"
},
{
"DeviceName": [],
"Input": "DVD"
}
],
"VolumeDevice": "JVC AV Receiver",
"ControlDevice": "Sony PS4",
"OutputDevice": "LG TV",
"UseMatrix": "true"
}, },
{ {
"Device": "Harman Kardon AV Receiver", "DisplayName": "Chromecast",
"Input": "Game" "DeviceSetupList": [
{
"DeviceName": "LG TV",
"Input": "HDMI1"
},
{
"DeviceName": "JVC AV Receiver",
"Input": "DVD"
},
{
"DeviceName": "Chromecast",
"Input": []
}
],
"VolumeDevice": "JVC AV Receiver",
"ControlDevice": "Chromecast",
"OutputDevice": "LG TV",
"UseMatrix": "true"
},
{
"DisplayName": "Apple TV",
"DeviceSetupList": [
{
"DeviceName": "Apple TV Gen 4",
"Input": []
},
{
"DeviceName": "LG TV",
"Input": "HDMI1"
},
{
"DeviceName": "JVC AV Receiver",
"Input": "DVD"
}
],
"VolumeDevice": "JVC AV Receiver",
"ControlDevice": "Apple TV Gen 4",
"OutputDevice": "LG TV",
"UseMatrix": "true"
},
{
"DisplayName": "Listen to Music",
"DeviceSetupList": [
{
"DeviceName": "JVC AV Receiver",
"Input": "DVD"
}
],
"VolumeDevice": "JVC AV Receiver",
"ControlDevice": [],
"OutputDevice": [],
"UseMatrix": "false"
} }
], ]
"VolumeDevice": "Harman Kardon AV Receiver",
"ControlDevice": "Microsoft Xbox One",
"OutputDevice": "Vizio TV",
"UseMatrix": "true"
}, },
{ {
"DisplayName": "Play PS4", "DisplayName": "Bedroom",
"DeviceSetupList": [ "Activities": [
{ {
"Device": "Sony PS4", "DisplayName": "Play Xbox One",
"Input": [] "DeviceSetupList": [
{
"DeviceName": "Microsoft Xbox One",
"Input": []
},
{
"DeviceName": "Vizio TV",
"Input": "HDMI1"
},
{
"DeviceName": "Harman Kardon AV Receiver",
"Input": "Game"
}
],
"VolumeDevice": "Harman Kardon AV Receiver",
"ControlDevice": "Microsoft Xbox One",
"OutputDevice": "Vizio TV",
"UseMatrix": "true"
}, },
{ {
"Device": "Vizio TV", "DisplayName": "Play PS4",
"Input": "HDMI1" "DeviceSetupList": [
{
"DeviceName": "Sony PS4",
"Input": []
},
{
"DeviceName": "Vizio TV",
"Input": "HDMI1"
},
{
"DeviceName": "Harman Kardon AV Receiver",
"Input": "DVD"
}
],
"VolumeDevice": "Harman Kardon AV Receiver",
"ControlDevice": "Sony PS4",
"OutputDevice": "LG TV",
"UseMatrix": "true"
}, },
{ {
"Device": "Harman Kardon AV Receiver", "DisplayName": "Chromecast",
"Input": "DVD" "DeviceSetupList": [
{
"DeviceName": "Vizio TV",
"Input": "HDMI1"
},
{
"DeviceName": "Harman Kardon AV Receiver",
"Input": "Game"
},
{
"DeviceName": "Chromecast",
"Input": []
}
],
"VolumeDevice": "Harman Kardon AV Receiver",
"ControlDevice": "Chromecast",
"OutputDevice": "Vizio TV",
"UseMatrix": "true"
},
{
"DisplayName": "Apple TV",
"DeviceSetupList": [
{
"DeviceName": "Apple TV Gen 4",
"Input": []
},
{
"DeviceName": "Vizio TV",
"Input": "HDMI1"
},
{
"DeviceName": "Harman Kardon AV Receiver",
"Input": "Game"
}
],
"VolumeDevice": "Harman Kardon AV Receiver",
"ControlDevice": "Apple TV Gen 4",
"OutputDevice": "Vizio TV",
"UseMatrix": "true"
} }
], ]
"VolumeDevice": "Harman Kardon AV Receiver",
"ControlDevice": "Sony PS4",
"OutputDevice": "LG TV",
"UseMatrix": "true"
}, },
{ {
"DisplayName": "Chromecast", "DisplayName": "Kitchen",
"DeviceSetupList": [ "Activities": [
{ {
"Device": "Vizio TV", "DisplayName": "Watch Apple Tv",
"Input": "HDMI1" "DeviceSetupList": [
{
"DeviceName": "Apple TV Gen 4",
"Input": []
},
{
"DeviceName": "Westinghouse TV",
"Input": "HDMI1"
}
],
"VolumeDevice": "Westinghouse TV",
"ControlDevice": "Apple TV Gen 4",
"OutputDevice": "Westinghouse TV",
"UseMatrix": "true"
}, },
{ {
"Device": "Harman Kardon AV Receiver", "DisplayName": "Play Xbox One",
"Input": "Game" "DeviceSetupList": [
{
"DeviceName": "Westinghouse TV",
"Input": "HDMI1"
},
{
"DeviceName": "Microsoft Xbox One",
"Input": []
}
],
"VolumeDevice": "Westinghouse TV",
"ControlDevice": "Microsoft Xbox One",
"OutputDevice": "Westinghouse TV",
"UseMatrix": "true"
}, },
{ {
"Device": "Chromecast", "DisplayName": "Chromecast",
"Input": [] "DeviceSetupList": [
{
"DeviceName": "Chromecast",
"Input": []
},
{
"DeviceName": "Westinghouse TV",
"Input": "HDMI1"
}
],
"VolumeDevice": "Westinghouse TV",
"ControlDevice": "Chromecast",
"OutputDevice": "Westinghouse TV",
"UseMatrix": "true"
} }
], ]
"VolumeDevice": "Harman Kardon AV Receiver",
"ControlDevice": "Chromecast",
"OutputDevice": "Vizio TV",
"UseMatrix": "true"
},
{
"DisplayName": "Apple TV",
"DeviceSetupList": [
{
"Device": "Apple TV Gen 4",
"Input": []
},
{
"Device": "Vizio TV",
"Input": "HDMI1"
},
{
"Device": "Harman Kardon AV Receiver",
"Input": "Game"
}
],
"VolumeDevice": "Harman Kardon AV Receiver",
"ControlDevice": "Apple TV Gen 4",
"OutputDevice": "Vizio TV",
"UseMatrix": "true"
}
]
},
{
"DisplayName": "Kitchen",
"Activities": [
{
"DisplayName": "Watch Apple Tv",
"DeviceSetupList": [
{
"Device": "Apple TV Gen 4",
"Input": []
},
{
"Device": "Westinghouse TV",
"Input": "HDMI1"
}
],
"VolumeDevice": "Westinghouse TV",
"ControlDevice": "Apple TV Gen 4",
"OutputDevice": "Westinghouse TV",
"UseMatrix": "true"
},
{
"DisplayName": "Play Xbox One",
"DeviceSetupList": [
{
"Device": "Westinghouse TV",
"Input": "HDMI1"
},
{
"Device": "Microsoft Xbox One",
"Input": []
}
],
"VolumeDevice": "Westinghouse TV",
"ControlDevice": "Microsoft Xbox One",
"OutputDevice": "Westinghouse TV",
"UseMatrix": "true"
},
{
"DisplayName": "Chromecast",
"DeviceSetupList": [
{
"Device": "Chromecast",
"Input": []
},
{
"Device": "Westinghouse TV",
"Input": "HDMI1"
}
],
"VolumeDevice": "Westinghouse TV",
"ControlDevice": "Chromecast",
"OutputDevice": "Westinghouse TV",
"UseMatrix": "true"
} }
] ]
} }

View File

@ -14,15 +14,33 @@ export interface IControlUnitProps {
log: any, log: any,
} }
/**
* ControlUnit accessory
*/
export class ControlUnit implements IAccessory { export class ControlUnit implements IAccessory {
//Required by homebridge
name: string = ""; name: string = "";
//fields
private log: any = {}; private log: any = {};
private displayName: string = ""; private displayName: string = "";
//Service fields
private televisionService: HAPNodeJS.Service | undefined; private televisionService: HAPNodeJS.Service | undefined;
private televisionSpeakerService: HAPNodeJS.Service | undefined; private televisionSpeakerService: HAPNodeJS.Service | undefined;
private informationService: HAPNodeJS.Service | undefined; private informationService: HAPNodeJS.Service | undefined;
private inputServices: Array<HAPNodeJS.Service | undefined> = [];
//Harmony fields
private activities: Array<Activity> = [];
private matrix: Matrix;
/**
* Constructor
* @param props Input properties
*/
constructor(props: IControlUnitProps) { constructor(props: IControlUnitProps) {
//Assign class variables
this.log = props.log; this.log = props.log;
Api = props.api; Api = props.api;
Service = props.api.hap.Service; Service = props.api.hap.Service;
@ -30,11 +48,19 @@ export class ControlUnit implements IAccessory {
this.displayName = props.displayName; this.displayName = props.displayName;
this.name = this.displayName; this.name = this.displayName;
this.activities = props.activities;
this.matrix = props.matrix;
//Configure services
this.configureTvService(); this.configureTvService();
this.configureTvSpeakerService(); this.configureTvSpeakerService();
// this.configureAccessoryInformation(); // this.configureAccessoryInformation();
this.configureInputSourceService();
} }
/**
* Configure television service
*/
private configureTvService(): void { private configureTvService(): void {
this.televisionService = new Service.Television( this.televisionService = new Service.Television(
this.displayName, this.displayName,
@ -48,6 +74,9 @@ export class ControlUnit implements IAccessory {
this.televisionService.setCharacteristic(Characteristic.Active, false); this.televisionService.setCharacteristic(Characteristic.Active, false);
} }
/**
* Configure Speaker Service
*/
private configureTvSpeakerService(): void { private configureTvSpeakerService(): void {
this.televisionSpeakerService = new Service.TelevisionSpeaker( this.televisionSpeakerService = new Service.TelevisionSpeaker(
this.displayName, this.displayName,
@ -65,6 +94,9 @@ export class ControlUnit implements IAccessory {
} }
} }
/**
* Configure information service
*/
private configureAccessoryInformation(): void { private configureAccessoryInformation(): void {
this.informationService = new Service.AccessoryInformation(this.displayName, 'information'); this.informationService = new Service.AccessoryInformation(this.displayName, 'information');
this.informationService this.informationService
@ -72,11 +104,50 @@ export class ControlUnit implements IAccessory {
.setCharacteristic(Characteristic.Model, 'Heater-Cooler') .setCharacteristic(Characteristic.Model, 'Heater-Cooler')
} }
/**
* Configure input service
*/
private configureInputSourceService(): void {
let inputs: Array<HAPNodeJS.Service> = [];
this.activities.forEach((activity: Activity, index: number) => {
this.log(activity.displayName);
let uuid: string = Api.hap.uuid.generate(activity.displayName + this.rand(1, 10).toString());
let inputService = new Service.InputSource(activity.displayName, 'activity' + activity.displayName);
inputService
.setCharacteristic(Characteristic.Identifier, index)
.setCharacteristic(
Characteristic.ConfiguredName,
activity.displayName)
.setCharacteristic(
Characteristic.IsConfigured,
//@ts-ignore
Characteristic.IsConfigured.CONFIGURED
)
//@ts-ignore
.setCharacteristic(Characteristic.InputSourceType, Characteristic.InputSourceType.HDMI);
//@ts-ignore
this.televisionService!.addLinkedService(inputService);
inputs.push(inputService);
});
this.inputServices = inputs;
}
/** /**
* Called by homebridge to gather services for this accessory. * Called by homebridge to gather services for this accessory.
*/ */
getServices(): Array<HAPNodeJS.Service> { getServices(): Array<HAPNodeJS.Service> {
this.log(`${this.displayName}`) this.log(`${this.displayName}`)
return ([this.televisionService!, this.televisionSpeakerService!]); let services: Array<HAPNodeJS.Service> = [this.televisionService!, this.televisionSpeakerService!];
this.inputServices.forEach((service: HAPNodeJS.Service | undefined) => {
services.push(service!);
});
return (services);
}
private rand(min: number, max: number): number {
var random = Math.floor(Math.random() * (+max - +min)) + +min;
return random;
} }
} }