Added device emit option for debugging purposes
This commit is contained in:
42
src/index.ts
42
src/index.ts
@@ -1,12 +1,13 @@
|
||||
import { ControlUnit } from "./Accessories/ControlUnit";
|
||||
import { DeviceButton } from './Accessories/DeviceButton';
|
||||
import { IActivity } from "./Models/Activity";
|
||||
import { IDeviceSetupItem } from "./Models/DeviceSetupItem";
|
||||
import { IInput, IOutput, IMatrix } from "./Models/Matrix";
|
||||
import { IActivity } from "./Models/Config/IActivity";
|
||||
import { IDeviceSetupItem } from "./Models/Config/IDeviceSetupItem";
|
||||
import { IInput, IOutput, IMatrix } from "./Models/Config/IMatrix";
|
||||
import HarmonyDataProvider from "./DataProviders/HarmonyDataProvider";
|
||||
import { IConfig, IControlUnit } from "./Models/IConfig";
|
||||
import { IDeviceButton } from "./Models/DeviceButton";
|
||||
import { IConfig, IControlUnit } from "./Models/Config/IConfig";
|
||||
import { IDeviceButton } from "./Models/Config/IDeviceButton";
|
||||
import { IAccessory } from "./Accessories/IAccessory";
|
||||
import { IDevice, ICommand } from "./Models/IDevice";
|
||||
|
||||
let Accessory: any;
|
||||
let Homebridge: any;
|
||||
@@ -41,6 +42,28 @@ class HarmonyMatrixPlatform {
|
||||
this.api.on('didFinishLaunching', this.didFinishLaunching.bind(this));
|
||||
|
||||
this.dataProvider = null;
|
||||
|
||||
if (this.config) {
|
||||
//construct data provider
|
||||
this.dataProvider = new HarmonyDataProvider({
|
||||
hubAddress: this.config.hubIp,
|
||||
matrix: this.config.Matrix,
|
||||
log: this.log
|
||||
});
|
||||
|
||||
//Emit devices if requested
|
||||
if (this.config.EmitDevicesOnStartup) {
|
||||
this.dataProvider.on("Ready", () => {
|
||||
const devices: { [name: string]: IDevice } = this.dataProvider!.devices;
|
||||
Object.values(devices).forEach((device: IDevice) => {
|
||||
this.log(`${device.name} : ${device.id}`);
|
||||
Object.keys(device.commands).forEach((command: string) => {
|
||||
this.log(` ${command}`);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,12 +86,6 @@ class HarmonyMatrixPlatform {
|
||||
* @param callback
|
||||
*/
|
||||
accessories(callback: (accessories: Array<IAccessory>) => void) {
|
||||
//construct data provider
|
||||
this.dataProvider = new HarmonyDataProvider({
|
||||
hubAddress: this.config.hubIp,
|
||||
matrix: this.config.Matrix,
|
||||
log: this.log
|
||||
});
|
||||
|
||||
//Add control units
|
||||
this.config.ControlUnits.forEach((unit: IControlUnit) => {
|
||||
@@ -86,7 +103,8 @@ class HarmonyMatrixPlatform {
|
||||
this.config.DeviceButtons.forEach((button: IDeviceButton) => {
|
||||
this.accessoryList.push(new DeviceButton({
|
||||
dataProvider: this.dataProvider!,
|
||||
name: button.ButtonName,
|
||||
buttonName: button.ButtonName,
|
||||
displayName: button.DisplayName,
|
||||
deviceInfo: button,
|
||||
api: this.api,
|
||||
log: this.log,
|
||||
|
||||
Reference in New Issue
Block a user