First pass done but untested
This commit is contained in:
parent
ba1a1685ae
commit
ec0c857c97
@ -26,10 +26,10 @@ interface IHarmonyDataProviderProps {
|
|||||||
|
|
||||||
class HarmonyDataProvider extends EventEmitter {
|
class HarmonyDataProvider extends EventEmitter {
|
||||||
private _log: any;
|
private _log: any;
|
||||||
private _deviceConfigs: Array<IDeviceConfig>;
|
private _hubsByDevice: { [deviceName: string]: string } = {};
|
||||||
private _hubs: { [hubName: string]: IHub } = {};
|
private _hubs: { [hubName: string]: IHub } = {};
|
||||||
|
private _devicesByHub: { [hubName: string]: { [deviceName: string]: HarmonyDevice } } = {};
|
||||||
private _devices: { [name: string]: HarmonyDevice; } = {};
|
// private _devices: { [name: string]: HarmonyDevice; } = {};
|
||||||
private _states: { [controlUnitName: string]: (IActivityState | undefined) } = {};
|
private _states: { [controlUnitName: string]: (IActivityState | undefined) } = {};
|
||||||
|
|
||||||
private _matrix: IMatrix;
|
private _matrix: IMatrix;
|
||||||
@ -43,13 +43,16 @@ class HarmonyDataProvider extends EventEmitter {
|
|||||||
this._hubs[value.Name] = value;
|
this._hubs[value.Name] = value;
|
||||||
});
|
});
|
||||||
this._matrix = props.matrix;
|
this._matrix = props.matrix;
|
||||||
this._deviceConfigs = props.deviceConfigs;
|
props.deviceConfigs.forEach((deviceConfig: IDeviceConfig) => {
|
||||||
|
this._hubsByDevice[deviceConfig.Name] = deviceConfig.Hub;
|
||||||
|
});
|
||||||
|
// this._deviceConfigs = props.deviceConfigs;
|
||||||
|
|
||||||
this.connect();
|
this.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public get devices(): { [name: string]: HarmonyDevice; } {
|
public get devicesByHub(): { [hubName: string]: { [deviceName: string]: HarmonyDevice } } {
|
||||||
return this._devices;
|
return this._devicesByHub;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -107,7 +110,7 @@ class HarmonyDataProvider extends EventEmitter {
|
|||||||
|
|
||||||
//Turn on devices
|
//Turn on devices
|
||||||
await Promise.all(devicesToTurnOn.map(async (device: HarmonyDevice) => {
|
await Promise.all(devicesToTurnOn.map(async (device: HarmonyDevice) => {
|
||||||
if (device && device.name && this._devices[device.name]) {
|
if (device && device.name) {
|
||||||
if (!device.on) {
|
if (!device.on) {
|
||||||
this._log(`Turning on device ${device.name}`)
|
this._log(`Turning on device ${device.name}`)
|
||||||
await device.powerOn();
|
await device.powerOn();
|
||||||
@ -307,7 +310,7 @@ class HarmonyDataProvider extends EventEmitter {
|
|||||||
deviceCommands.forEach((command: any) => {
|
deviceCommands.forEach((command: any) => {
|
||||||
commands[command.label] = command.action;
|
commands[command.label] = command.action;
|
||||||
});
|
});
|
||||||
self._devices[dev.label] = new HarmonyDevice({
|
self._devicesByHub[hub.Name][dev.label] = new HarmonyDevice({
|
||||||
id: dev.id,
|
id: dev.id,
|
||||||
name: dev.label,
|
name: dev.label,
|
||||||
commands: commands,
|
commands: commands,
|
||||||
@ -333,7 +336,7 @@ class HarmonyDataProvider extends EventEmitter {
|
|||||||
* @param deviceName The device to retrieve.
|
* @param deviceName The device to retrieve.
|
||||||
*/
|
*/
|
||||||
private getDeviceFromName(deviceName: string): HarmonyDevice {
|
private getDeviceFromName(deviceName: string): HarmonyDevice {
|
||||||
return this._devices[deviceName];
|
return this._devicesByHub[this._hubsByDevice[deviceName]][deviceName];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,6 +30,10 @@ export class HarmonyDevice {
|
|||||||
return this._on;
|
return this._on;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get commands(): { [name: string]: ICommand } {
|
||||||
|
return this._commands;
|
||||||
|
}
|
||||||
|
|
||||||
//Define device methods
|
//Define device methods
|
||||||
public supportsCommand(commandName: string): boolean {
|
public supportsCommand(commandName: string): boolean {
|
||||||
let command = this._commands[commandName];
|
let command = this._commands[commandName];
|
||||||
|
18
src/index.ts
18
src/index.ts
@ -2,6 +2,7 @@ import * as Accessories from "./Accessories";
|
|||||||
import HarmonyDataProvider from "./DataProviders/HarmonyDataProvider";
|
import HarmonyDataProvider from "./DataProviders/HarmonyDataProvider";
|
||||||
import * as Config from "./Models/Config";
|
import * as Config from "./Models/Config";
|
||||||
import { IDevice } from "./Models";
|
import { IDevice } from "./Models";
|
||||||
|
import { HarmonyDevice } from "./Models/HarmonyDevice";
|
||||||
|
|
||||||
let Accessory: any;
|
let Accessory: any;
|
||||||
let Homebridge: any;
|
let Homebridge: any;
|
||||||
@ -49,13 +50,20 @@ class HarmonyMatrixPlatform {
|
|||||||
//Emit devices if requested
|
//Emit devices if requested
|
||||||
if (this.config.EmitDevicesOnStartup) {
|
if (this.config.EmitDevicesOnStartup) {
|
||||||
this.dataProvider.on("Ready", () => {
|
this.dataProvider.on("Ready", () => {
|
||||||
const devices: { [name: string]: IDevice } = this.dataProvider!.devices;
|
|
||||||
Object.values(devices).forEach((device: IDevice) => {
|
const hubs: { [hubName: string]: { [deviceName: string]: HarmonyDevice } } = this.dataProvider!.devicesByHub;
|
||||||
this.log(`${device.name} : ${device.id}`);
|
Object.keys(hubs).forEach((hubName: string) => {
|
||||||
Object.keys(device.commands).forEach((command: string) => {
|
const deviceDictionary = hubs[hubName];
|
||||||
this.log(` ${command}`);
|
this.log(`${hubName}`)
|
||||||
|
|
||||||
|
Object.values(deviceDictionary).forEach((device: HarmonyDevice) => {
|
||||||
|
this.log(` ${device.name} : ${device.id}`);
|
||||||
|
Object.keys(device.commands).forEach((command: string) => {
|
||||||
|
this.log(` ${command}`);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user