Code re-organization

This commit is contained in:
watsonb8 2020-01-01 23:39:07 -05:00
parent 020a2fc240
commit 672362a9a4
6 changed files with 28 additions and 27 deletions

View File

@ -1,5 +1,4 @@
import { IActivity } from '../Models/Config/IActivity';
import { IMatrix } from '../Models/Config/IMatrix';
import * as Config from "../Models/Config"
import { IAccessory } from './IAccessory';
import callbackify from '../Util/Callbackify';
import HarmonyDataProvider from '../DataProviders/HarmonyDataProvider';
@ -31,7 +30,7 @@ export enum RemoteKey {
export interface IControlUnitProps {
dataProvider: HarmonyDataProvider,
displayName: string,
activities: Array<IActivity>,
activities: Array<Config.IActivity>,
api: any,
log: any,
homebridge: any,
@ -55,7 +54,7 @@ export class ControlUnit implements IAccessory {
private inputServices: Array<HAPNodeJS.Service | undefined> = [];
//Harmony fields
private activities: Array<IActivity> = [];
private activities: Array<Config.IActivity> = [];
private dataProvider: HarmonyDataProvider;
public platformAccessory: any;
@ -180,7 +179,7 @@ export class ControlUnit implements IAccessory {
* Event handler for GET active identifier characteristic
*/
private onGetActiveIdentifier = async () => {
let currentActivity: IActivity = this.dataProvider.getIsActive(this.name)!;
let currentActivity: Config.IActivity = this.dataProvider.getIsActive(this.name)!;
let identifier: number = 0;
if (currentActivity) {
identifier = this.activities.findIndex(e => e.DisplayName === currentActivity.DisplayName);
@ -240,7 +239,7 @@ export class ControlUnit implements IAccessory {
*/
private configureInputSourceService(): void {
let inputs: Array<HAPNodeJS.Service> = [];
this.activities.forEach((activity: IActivity, index: number) => {
this.activities.forEach((activity: Config.IActivity, index: number) => {
let inputService = new Service.InputSource(activity.DisplayName, 'activity' + activity.DisplayName);
inputService
.setCharacteristic(Characteristic.Identifier, index)

View File

@ -1,8 +1,7 @@
import HarmonyDataProvider from "../DataProviders/HarmonyDataProvider";
import { IDeviceButton } from "../Models/Config/IDeviceButton";
import { IDeviceButton } from "../Models/Config";
import { IAccessory } from "./IAccessory";
import { sleep } from "../Util/Sleep";
import { ICommand } from "../Models/IDevice";
import { ICommand } from "../Models";
let Service: HAPNodeJS.Service;
let Characteristic: HAPNodeJS.Characteristic;

3
src/Accessories/index.ts Normal file
View File

@ -0,0 +1,3 @@
export { ControlUnit } from './ControlUnit';
export { DeviceButton } from './DeviceButton';
export { IAccessory } from './IAccessory';

View File

@ -0,0 +1,5 @@
export * from './IActivity';
export * from './IConfig';
export * from './IDeviceButton';
export * from './IDeviceSetupItem';
export * from './IMatrix';

1
src/Models/index.ts Normal file
View File

@ -0,0 +1 @@
export * from './IDevice';

View File

@ -1,13 +1,7 @@
import { ControlUnit } from "./Accessories/ControlUnit";
import { DeviceButton } from './Accessories/DeviceButton';
import { IActivity } from "./Models/Config/IActivity";
import { IDeviceSetupItem } from "./Models/Config/IDeviceSetupItem";
import { IInput, IOutput, IMatrix } from "./Models/Config/IMatrix";
import * as Accessories from "./Accessories";
import HarmonyDataProvider from "./DataProviders/HarmonyDataProvider";
import { IConfig, IControlUnit } from "./Models/Config/IConfig";
import { IDeviceButton } from "./Models/Config/IDeviceButton";
import { IAccessory } from "./Accessories/IAccessory";
import { IDevice, ICommand } from "./Models/IDevice";
import * as Config from "./Models/Config";
import { IDevice } from "./Models";
let Accessory: any;
let Homebridge: any;
@ -29,10 +23,10 @@ export default function (homebridge: any) {
class HarmonyMatrixPlatform {
log: any = {};
config: IConfig;
config: Config.IConfig;
api: any;
dataProvider: HarmonyDataProvider | null;
accessoryList: Array<IAccessory> = [];
accessoryList: Array<Accessories.IAccessory> = [];
constructor(log: any, config: any, api: any) {
this.log = log;
@ -74,8 +68,8 @@ class HarmonyMatrixPlatform {
this.log(`Publishing external accessories`);
//This is required in order to have multiple tv remotes on one platform
this.accessoryList.forEach((accessory: IAccessory) => {
if (accessory instanceof ControlUnit) {
this.accessoryList.forEach((accessory: Accessories.IAccessory) => {
if (accessory instanceof Accessories.ControlUnit) {
this.api.publishExternalAccessories("HarmonyMatrixPlatform", [accessory.platformAccessory]);
}
})
@ -85,11 +79,11 @@ class HarmonyMatrixPlatform {
* Called by homebridge to gather accessories.
* @param callback
*/
accessories(callback: (accessories: Array<IAccessory>) => void) {
accessories(callback: (accessories: Array<Accessories.IAccessory>) => void) {
//Add control units
this.config.ControlUnits.forEach((unit: IControlUnit) => {
this.accessoryList.push(new ControlUnit({
this.config.ControlUnits.forEach((unit: Config.IControlUnit) => {
this.accessoryList.push(new Accessories.ControlUnit({
dataProvider: this.dataProvider!,
displayName: unit.DisplayName,
api: this.api,
@ -100,8 +94,8 @@ class HarmonyMatrixPlatform {
});
//Add device buttons
this.config.DeviceButtons.forEach((button: IDeviceButton) => {
this.accessoryList.push(new DeviceButton({
this.config.DeviceButtons.forEach((button: Config.IDeviceButton) => {
this.accessoryList.push(new Accessories.DeviceButton({
dataProvider: this.dataProvider!,
buttonName: button.ButtonName,
displayName: button.DisplayName,