Code re-organization
This commit is contained in:
parent
020a2fc240
commit
672362a9a4
@ -1,5 +1,4 @@
|
|||||||
import { IActivity } from '../Models/Config/IActivity';
|
import * as Config from "../Models/Config"
|
||||||
import { IMatrix } from '../Models/Config/IMatrix';
|
|
||||||
import { IAccessory } from './IAccessory';
|
import { IAccessory } from './IAccessory';
|
||||||
import callbackify from '../Util/Callbackify';
|
import callbackify from '../Util/Callbackify';
|
||||||
import HarmonyDataProvider from '../DataProviders/HarmonyDataProvider';
|
import HarmonyDataProvider from '../DataProviders/HarmonyDataProvider';
|
||||||
@ -31,7 +30,7 @@ export enum RemoteKey {
|
|||||||
export interface IControlUnitProps {
|
export interface IControlUnitProps {
|
||||||
dataProvider: HarmonyDataProvider,
|
dataProvider: HarmonyDataProvider,
|
||||||
displayName: string,
|
displayName: string,
|
||||||
activities: Array<IActivity>,
|
activities: Array<Config.IActivity>,
|
||||||
api: any,
|
api: any,
|
||||||
log: any,
|
log: any,
|
||||||
homebridge: any,
|
homebridge: any,
|
||||||
@ -55,7 +54,7 @@ export class ControlUnit implements IAccessory {
|
|||||||
private inputServices: Array<HAPNodeJS.Service | undefined> = [];
|
private inputServices: Array<HAPNodeJS.Service | undefined> = [];
|
||||||
|
|
||||||
//Harmony fields
|
//Harmony fields
|
||||||
private activities: Array<IActivity> = [];
|
private activities: Array<Config.IActivity> = [];
|
||||||
private dataProvider: HarmonyDataProvider;
|
private dataProvider: HarmonyDataProvider;
|
||||||
|
|
||||||
public platformAccessory: any;
|
public platformAccessory: any;
|
||||||
@ -180,7 +179,7 @@ export class ControlUnit implements IAccessory {
|
|||||||
* Event handler for GET active identifier characteristic
|
* Event handler for GET active identifier characteristic
|
||||||
*/
|
*/
|
||||||
private onGetActiveIdentifier = async () => {
|
private onGetActiveIdentifier = async () => {
|
||||||
let currentActivity: IActivity = this.dataProvider.getIsActive(this.name)!;
|
let currentActivity: Config.IActivity = this.dataProvider.getIsActive(this.name)!;
|
||||||
let identifier: number = 0;
|
let identifier: number = 0;
|
||||||
if (currentActivity) {
|
if (currentActivity) {
|
||||||
identifier = this.activities.findIndex(e => e.DisplayName === currentActivity.DisplayName);
|
identifier = this.activities.findIndex(e => e.DisplayName === currentActivity.DisplayName);
|
||||||
@ -240,7 +239,7 @@ export class ControlUnit implements IAccessory {
|
|||||||
*/
|
*/
|
||||||
private configureInputSourceService(): void {
|
private configureInputSourceService(): void {
|
||||||
let inputs: Array<HAPNodeJS.Service> = [];
|
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);
|
let inputService = new Service.InputSource(activity.DisplayName, 'activity' + activity.DisplayName);
|
||||||
inputService
|
inputService
|
||||||
.setCharacteristic(Characteristic.Identifier, index)
|
.setCharacteristic(Characteristic.Identifier, index)
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
import HarmonyDataProvider from "../DataProviders/HarmonyDataProvider";
|
import HarmonyDataProvider from "../DataProviders/HarmonyDataProvider";
|
||||||
import { IDeviceButton } from "../Models/Config/IDeviceButton";
|
import { IDeviceButton } from "../Models/Config";
|
||||||
import { IAccessory } from "./IAccessory";
|
import { IAccessory } from "./IAccessory";
|
||||||
import { sleep } from "../Util/Sleep";
|
import { ICommand } from "../Models";
|
||||||
import { ICommand } from "../Models/IDevice";
|
|
||||||
|
|
||||||
let Service: HAPNodeJS.Service;
|
let Service: HAPNodeJS.Service;
|
||||||
let Characteristic: HAPNodeJS.Characteristic;
|
let Characteristic: HAPNodeJS.Characteristic;
|
||||||
|
3
src/Accessories/index.ts
Normal file
3
src/Accessories/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export { ControlUnit } from './ControlUnit';
|
||||||
|
export { DeviceButton } from './DeviceButton';
|
||||||
|
export { IAccessory } from './IAccessory';
|
5
src/Models/Config/index.ts
Normal file
5
src/Models/Config/index.ts
Normal 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
1
src/Models/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './IDevice';
|
30
src/index.ts
30
src/index.ts
@ -1,13 +1,7 @@
|
|||||||
import { ControlUnit } from "./Accessories/ControlUnit";
|
import * as Accessories from "./Accessories";
|
||||||
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 HarmonyDataProvider from "./DataProviders/HarmonyDataProvider";
|
import HarmonyDataProvider from "./DataProviders/HarmonyDataProvider";
|
||||||
import { IConfig, IControlUnit } from "./Models/Config/IConfig";
|
import * as Config from "./Models/Config";
|
||||||
import { IDeviceButton } from "./Models/Config/IDeviceButton";
|
import { IDevice } from "./Models";
|
||||||
import { IAccessory } from "./Accessories/IAccessory";
|
|
||||||
import { IDevice, ICommand } from "./Models/IDevice";
|
|
||||||
|
|
||||||
let Accessory: any;
|
let Accessory: any;
|
||||||
let Homebridge: any;
|
let Homebridge: any;
|
||||||
@ -29,10 +23,10 @@ export default function (homebridge: any) {
|
|||||||
|
|
||||||
class HarmonyMatrixPlatform {
|
class HarmonyMatrixPlatform {
|
||||||
log: any = {};
|
log: any = {};
|
||||||
config: IConfig;
|
config: Config.IConfig;
|
||||||
api: any;
|
api: any;
|
||||||
dataProvider: HarmonyDataProvider | null;
|
dataProvider: HarmonyDataProvider | null;
|
||||||
accessoryList: Array<IAccessory> = [];
|
accessoryList: Array<Accessories.IAccessory> = [];
|
||||||
|
|
||||||
constructor(log: any, config: any, api: any) {
|
constructor(log: any, config: any, api: any) {
|
||||||
this.log = log;
|
this.log = log;
|
||||||
@ -74,8 +68,8 @@ class HarmonyMatrixPlatform {
|
|||||||
this.log(`Publishing external accessories`);
|
this.log(`Publishing external accessories`);
|
||||||
|
|
||||||
//This is required in order to have multiple tv remotes on one platform
|
//This is required in order to have multiple tv remotes on one platform
|
||||||
this.accessoryList.forEach((accessory: IAccessory) => {
|
this.accessoryList.forEach((accessory: Accessories.IAccessory) => {
|
||||||
if (accessory instanceof ControlUnit) {
|
if (accessory instanceof Accessories.ControlUnit) {
|
||||||
this.api.publishExternalAccessories("HarmonyMatrixPlatform", [accessory.platformAccessory]);
|
this.api.publishExternalAccessories("HarmonyMatrixPlatform", [accessory.platformAccessory]);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -85,11 +79,11 @@ class HarmonyMatrixPlatform {
|
|||||||
* Called by homebridge to gather accessories.
|
* Called by homebridge to gather accessories.
|
||||||
* @param callback
|
* @param callback
|
||||||
*/
|
*/
|
||||||
accessories(callback: (accessories: Array<IAccessory>) => void) {
|
accessories(callback: (accessories: Array<Accessories.IAccessory>) => void) {
|
||||||
|
|
||||||
//Add control units
|
//Add control units
|
||||||
this.config.ControlUnits.forEach((unit: IControlUnit) => {
|
this.config.ControlUnits.forEach((unit: Config.IControlUnit) => {
|
||||||
this.accessoryList.push(new ControlUnit({
|
this.accessoryList.push(new Accessories.ControlUnit({
|
||||||
dataProvider: this.dataProvider!,
|
dataProvider: this.dataProvider!,
|
||||||
displayName: unit.DisplayName,
|
displayName: unit.DisplayName,
|
||||||
api: this.api,
|
api: this.api,
|
||||||
@ -100,8 +94,8 @@ class HarmonyMatrixPlatform {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//Add device buttons
|
//Add device buttons
|
||||||
this.config.DeviceButtons.forEach((button: IDeviceButton) => {
|
this.config.DeviceButtons.forEach((button: Config.IDeviceButton) => {
|
||||||
this.accessoryList.push(new DeviceButton({
|
this.accessoryList.push(new Accessories.DeviceButton({
|
||||||
dataProvider: this.dataProvider!,
|
dataProvider: this.dataProvider!,
|
||||||
buttonName: button.ButtonName,
|
buttonName: button.ButtonName,
|
||||||
displayName: button.DisplayName,
|
displayName: button.DisplayName,
|
||||||
|
Loading…
Reference in New Issue
Block a user