Added device buttons
This commit is contained in:
31
src/index.ts
31
src/index.ts
@@ -1,9 +1,12 @@
|
||||
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 HarmonyDataProvider from "./DataProviders/HarmonyDataProvider";
|
||||
import { IConfig, IControlUnit } from "./Models/IConfig";
|
||||
import { IDeviceButton } from "./Models/DeviceButton";
|
||||
import { IAccessory } from "./Accessories/IAccessory";
|
||||
|
||||
let Accessory: any;
|
||||
let Homebridge: any;
|
||||
@@ -28,7 +31,7 @@ class HarmonyMatrixPlatform {
|
||||
config: IConfig;
|
||||
api: any;
|
||||
dataProvider: HarmonyDataProvider | null;
|
||||
controlUnits: Array<ControlUnit> = [];
|
||||
accessoryList: Array<IAccessory> = [];
|
||||
|
||||
constructor(log: any, config: any, api: any) {
|
||||
this.log = log;
|
||||
@@ -48,8 +51,10 @@ class HarmonyMatrixPlatform {
|
||||
this.log(`Publishing external accessories`);
|
||||
|
||||
//This is required in order to have multiple tv remotes on one platform
|
||||
this.controlUnits.forEach((accessory: ControlUnit) => {
|
||||
this.api.publishExternalAccessories("HarmonyMatrixPlatform", [accessory.platformAccessory]);
|
||||
this.accessoryList.forEach((accessory: IAccessory) => {
|
||||
if (accessory instanceof ControlUnit) {
|
||||
this.api.publishExternalAccessories("HarmonyMatrixPlatform", [accessory.platformAccessory]);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -57,7 +62,7 @@ class HarmonyMatrixPlatform {
|
||||
* Called by homebridge to gather accessories.
|
||||
* @param callback
|
||||
*/
|
||||
accessories(callback: (accessories: Array<ControlUnit>) => void) {
|
||||
accessories(callback: (accessories: Array<IAccessory>) => void) {
|
||||
//construct data provider
|
||||
this.dataProvider = new HarmonyDataProvider({
|
||||
hubAddress: this.config.hubIp,
|
||||
@@ -65,8 +70,9 @@ class HarmonyMatrixPlatform {
|
||||
log: this.log
|
||||
});
|
||||
|
||||
//Add control units
|
||||
this.config.ControlUnits.forEach((unit: IControlUnit) => {
|
||||
this.controlUnits.push(new ControlUnit({
|
||||
this.accessoryList.push(new ControlUnit({
|
||||
dataProvider: this.dataProvider!,
|
||||
displayName: unit.DisplayName,
|
||||
api: this.api,
|
||||
@@ -75,6 +81,19 @@ class HarmonyMatrixPlatform {
|
||||
homebridge: Homebridge,
|
||||
}));
|
||||
});
|
||||
callback(this.controlUnits);
|
||||
|
||||
//Add device buttons
|
||||
this.config.DeviceButtons.forEach((button: IDeviceButton) => {
|
||||
this.accessoryList.push(new DeviceButton({
|
||||
dataProvider: this.dataProvider!,
|
||||
name: button.ButtonName,
|
||||
deviceInfo: button,
|
||||
api: this.api,
|
||||
log: this.log,
|
||||
homebridge: Homebridge,
|
||||
|
||||
}))
|
||||
});
|
||||
callback(this.accessoryList);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user