import { ControlUnit } from "./Accessories/ControlUnit"; import { Activity } from "./Models/Activity"; import { DeviceSetupItem } from "./Models/DeviceSetupItem"; import { Input, Output, Matrix } from "./Models/Matrix"; export default function (homebridge: any) { homebridge.registerPlatform( 'homebridge-harmony-watson', 'HarmonyHubMatrix', HarmonyMatrixPlatform, true ); }; class HarmonyMatrixPlatform { log: any = {}; config: any = {}; api: any; constructor(log: any, config: any, api: any) { this.log = log; this.config = config; this.api = api; this.log('INFO - Registering Harmony Matrix Platform'); } /** * Called by homebridge to gather accessories. * @param callback */ accessories(callback: (accessories: Array) => void) { //Parse matrix let configInputs: any = this.config["Matrix"]["Inputs"]; let configOutputs: any = this.config["Matrix"]["Outputs"]; let inputs: Array = []; let outputs: Array = []; configInputs.forEach((configInput: any) => { let inputDevice: string = configInput["InputDevice"]; let inputNumber: string = configInput["InputNumber"]; this.log(`INFO - Added input to matrix '${inputDevice}'`); inputs.push({ inputDevice: inputDevice, inputNumber: inputNumber }); }); configOutputs.forEach((configOutput: any) => { let outputDevice: string = configOutput["OutputDevice"]; let outputLetter: string = configOutput["OutputLetter"]; this.log(`INFO - Added output to matrix '${outputDevice}'`); outputs.push({ outputDevice: outputDevice, outputLetter: outputLetter }); }); let matrix = new Matrix({ inputs: inputs, outputs: outputs, }); //Parse control units let configControlUnits: any = this.config["ControlUnits"]; let controlUnits: Array = []; configControlUnits.forEach((configControlUnit: any) => { //Parse activities list let configActivities: any = configControlUnit["Activities"]; let activities: Array = []; configActivities.forEach((configActivity: any) => { //parse devices let configDevices: any = configActivity["DeviceSetupList"]; let devices: Array = []; configDevices.forEach((configDevice: any) => { //Add device devices.push(new DeviceSetupItem({ deviceId: configDevice["DeviceName"], input: configDevice["Input"] })); this.log(`INFO - Added device '${configDevice["DeviceName"]}' for activity '${configActivity["DisplayName"]}'`); }); //Add activity activities.push(new Activity({ volumeDeviceId: configActivity["VolumeDevice"], controlDeviceId: configActivity["ControlDevice"], outputDeviceId: configActivity["OutputDevice"], displayName: configActivity["DisplayName"], useMatrix: configActivity["UseMatrix"], deviceList: devices })); this.log(`INFO - Added activity '${configActivity["DisplayName"]}'`); }); //Add control unit controlUnits.push(new ControlUnit({ displayName: configControlUnit["DisplayName"], api: this.api, log: this.log, activities: activities, matrix: matrix, })); this.log(`INFO - Added ControlUnit`); }); callback(controlUnits); } }