Progress commit
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
import { IMatrix } from "./IMatrix";
|
||||
import { IActivity } from "./IActivity";
|
||||
import { IDeviceButton } from "./IDeviceButton";
|
||||
import { IDeviceConfig } from "./IDeviceConfig";
|
||||
import { IHub } from './IHub';
|
||||
|
||||
export interface IControlUnit {
|
||||
DisplayName: string;
|
||||
@ -9,8 +11,10 @@ export interface IControlUnit {
|
||||
|
||||
export interface IConfig {
|
||||
hubIp: string;
|
||||
EmitDevicesOnStartup: boolean,
|
||||
Matrix: IMatrix
|
||||
ControlUnits: Array<IControlUnit>
|
||||
DeviceButtons: Array<IDeviceButton>
|
||||
EmitDevicesOnStartup: boolean;
|
||||
Matrix: IMatrix;
|
||||
ControlUnits: Array<IControlUnit>;
|
||||
DeviceButtons: Array<IDeviceButton>;
|
||||
Devices: Array<IDeviceConfig>;
|
||||
Hubs: Array<IHub>;
|
||||
}
|
@ -2,5 +2,6 @@ export interface IDeviceButton {
|
||||
DeviceName: string;
|
||||
ButtonName: string;
|
||||
DisplayName: string;
|
||||
NumberOfKeyPresses: number;
|
||||
IsStateful: boolean;
|
||||
}
|
4
src/Models/Config/IDeviceConfig.ts
Normal file
4
src/Models/Config/IDeviceConfig.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export interface IDeviceConfig {
|
||||
Name: string;
|
||||
Hub: string;
|
||||
}
|
5
src/Models/Config/IHub.ts
Normal file
5
src/Models/Config/IHub.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export interface IHub {
|
||||
Name: string;
|
||||
Ip: string;
|
||||
Harmony: any;
|
||||
}
|
79
src/Models/HarmonyDevice.ts
Normal file
79
src/Models/HarmonyDevice.ts
Normal file
@ -0,0 +1,79 @@
|
||||
import { ICommand } from "./IDevice";
|
||||
import { sleep } from "../Util/Sleep";
|
||||
|
||||
export interface IHarmonyDeviceProps {
|
||||
id: string;
|
||||
name: string;
|
||||
harmony: any;
|
||||
log: any;
|
||||
commands: { [name: string]: ICommand };
|
||||
}
|
||||
|
||||
export class HarmonyDevice {
|
||||
private _harmony: any;
|
||||
private _log: any;
|
||||
private _commands: { [name: string]: ICommand } = {};
|
||||
private _on: boolean;
|
||||
|
||||
constructor(props: IHarmonyDeviceProps) {
|
||||
this.id = props.id;
|
||||
this.name = props.name;
|
||||
this._harmony = props.harmony;
|
||||
this._on = false;
|
||||
this._commands = props.commands;
|
||||
}
|
||||
|
||||
public id: string;
|
||||
public name: string;
|
||||
|
||||
//Define device methods
|
||||
public supportsCommand(commandName: string): boolean {
|
||||
let command = this._commands[commandName];
|
||||
return (command) ? true : false;
|
||||
}
|
||||
|
||||
public getCommand(commandName: string): ICommand {
|
||||
return this._commands[commandName];
|
||||
}
|
||||
|
||||
public async powerOn(): Promise<void> {
|
||||
let powerOnCommand: string = "Power On";
|
||||
let powerToggleCommand: string = "Power Toggle";
|
||||
if (this.supportsCommand(powerOnCommand)) {
|
||||
await this.sendCommand(powerOnCommand);
|
||||
this._on = true;
|
||||
} else if (this.supportsCommand(powerToggleCommand)) {
|
||||
await this.sendCommand(powerToggleCommand);
|
||||
this._on = true;
|
||||
}
|
||||
}
|
||||
|
||||
public async powerOff(): Promise<void> {
|
||||
let powerOffCommand: string = "Power Off";
|
||||
let powerToggleCommand: string = "Power Toggle";
|
||||
if (this.supportsCommand(powerOffCommand)) {
|
||||
await this.sendCommand(powerOffCommand);
|
||||
this._on = false;
|
||||
} else if (this.supportsCommand(powerToggleCommand)) {
|
||||
await this.sendCommand(powerToggleCommand);
|
||||
this._on = false;
|
||||
}
|
||||
}
|
||||
|
||||
public async sendCommand(commandName: string): Promise<void> {
|
||||
let command!: ICommand;
|
||||
if (this.supportsCommand(commandName)) {
|
||||
command = this.getCommand(commandName);
|
||||
}
|
||||
|
||||
try {
|
||||
//Execute command
|
||||
await this._harmony.sendCommand(JSON.stringify(command));
|
||||
|
||||
//Sleep
|
||||
await sleep(800);
|
||||
} catch (err) {
|
||||
this._log(`ERROR - error sending command to harmony: ${err}`);
|
||||
}
|
||||
}
|
||||
}
|
@ -5,10 +5,15 @@ export interface ICommand {
|
||||
}
|
||||
|
||||
export interface IDevice {
|
||||
id: string,
|
||||
name: string,
|
||||
id: string;
|
||||
name: string;
|
||||
harmony: any;
|
||||
log: any
|
||||
supportsCommand(commandName: string): boolean,
|
||||
getCommand(commandName: string): ICommand,
|
||||
powerOn(): Promise<void>;
|
||||
powerOff(): Promise<void>;
|
||||
sendCommand(commandName: string): Promise<void>;
|
||||
commands: { [name: string]: ICommand };
|
||||
on: boolean;
|
||||
}
|
Reference in New Issue
Block a user