diff --git a/config.json b/config.json index ba30215..bf340fa 100644 --- a/config.json +++ b/config.json @@ -1,271 +1,300 @@ { - "platform": "HarmonyHubMatrix", - "ControlUnits": [ + "bridge": { + "name": "Homebridge", + "username": "CC:22:3D:E3:CE:42", + "port": 51826, + "pin": "031-45-154" + }, + "platforms": [ { - "DisplayName": "Living Room", - "Activities": [ - { - "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" - } - ] + "platform": "websocket", + "name": "websocket", + "port": 4050 }, { - "DisplayName": "Bedroom", - "Activities": [ + "platform": "HarmonyHubMatrix", + "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", - "DeviceSetupList": [ + "DisplayName": "Living Room", + "Activities": [ { - "Device": "Microsoft Xbox One", - "Input": [] + "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" }, { - "Device": "Vizio TV", - "Input": "HDMI1" + "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" }, { - "Device": "Harman Kardon AV Receiver", - "Input": "Game" + "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" } - ], - "VolumeDevice": "Harman Kardon AV Receiver", - "ControlDevice": "Microsoft Xbox One", - "OutputDevice": "Vizio TV", - "UseMatrix": "true" + ] }, { - "DisplayName": "Play PS4", - "DeviceSetupList": [ + "DisplayName": "Bedroom", + "Activities": [ { - "Device": "Sony PS4", - "Input": [] + "DisplayName": "Play Xbox One", + "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", - "Input": "HDMI1" + "DisplayName": "Play PS4", + "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", - "Input": "DVD" + "DisplayName": "Chromecast", + "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", - "DeviceSetupList": [ + "DisplayName": "Kitchen", + "Activities": [ { - "Device": "Vizio TV", - "Input": "HDMI1" + "DisplayName": "Watch Apple Tv", + "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", - "Input": "Game" + "DisplayName": "Play Xbox One", + "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", - "Input": [] + "DisplayName": "Chromecast", + "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" + ] } ] } diff --git a/src/Accessories/ControlUnit.ts b/src/Accessories/ControlUnit.ts index cd8a0ee..c10f221 100644 --- a/src/Accessories/ControlUnit.ts +++ b/src/Accessories/ControlUnit.ts @@ -14,15 +14,33 @@ export interface IControlUnitProps { log: any, } +/** + * ControlUnit accessory + */ export class ControlUnit implements IAccessory { + //Required by homebridge name: string = ""; + + //fields private log: any = {}; private displayName: string = ""; + + //Service fields private televisionService: HAPNodeJS.Service | undefined; private televisionSpeakerService: HAPNodeJS.Service | undefined; private informationService: HAPNodeJS.Service | undefined; + private inputServices: Array = []; + //Harmony fields + private activities: Array = []; + private matrix: Matrix; + + /** + * Constructor + * @param props Input properties + */ constructor(props: IControlUnitProps) { + //Assign class variables this.log = props.log; Api = props.api; Service = props.api.hap.Service; @@ -30,11 +48,19 @@ export class ControlUnit implements IAccessory { this.displayName = props.displayName; this.name = this.displayName; + this.activities = props.activities; + this.matrix = props.matrix; + + //Configure services this.configureTvService(); this.configureTvSpeakerService(); // this.configureAccessoryInformation(); + this.configureInputSourceService(); } + /** + * Configure television service + */ private configureTvService(): void { this.televisionService = new Service.Television( this.displayName, @@ -48,6 +74,9 @@ export class ControlUnit implements IAccessory { this.televisionService.setCharacteristic(Characteristic.Active, false); } + /** + * Configure Speaker Service + */ private configureTvSpeakerService(): void { this.televisionSpeakerService = new Service.TelevisionSpeaker( this.displayName, @@ -65,6 +94,9 @@ export class ControlUnit implements IAccessory { } } + /** + * Configure information service + */ private configureAccessoryInformation(): void { this.informationService = new Service.AccessoryInformation(this.displayName, 'information'); this.informationService @@ -72,11 +104,50 @@ export class ControlUnit implements IAccessory { .setCharacteristic(Characteristic.Model, 'Heater-Cooler') } + /** + * Configure input service + */ + private configureInputSourceService(): void { + let inputs: Array = []; + 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. */ getServices(): Array { this.log(`${this.displayName}`) - return ([this.televisionService!, this.televisionSpeakerService!]); + let services: Array = [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; } } \ No newline at end of file