Removing business logic from models. First pass at overrides feature
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@ -10,15 +10,12 @@ export interface IHarmonyDeviceProps {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@ -30,6 +27,10 @@ export class HarmonyDevice {
|
||||
return this._on;
|
||||
}
|
||||
|
||||
public set on(value: boolean) {
|
||||
this._on = value;
|
||||
}
|
||||
|
||||
public get commands(): { [name: string]: ICommand } {
|
||||
return this._commands;
|
||||
}
|
||||
@ -43,51 +44,4 @@ export class HarmonyDevice {
|
||||
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
|
||||
//HACK to fix Harmon Kardon receiver not turning off
|
||||
if (command.command === "PowerOff") {
|
||||
for (let i = 0; i < 2; i++) {
|
||||
await this._harmony.sendCommand(JSON.stringify(command));
|
||||
}
|
||||
}
|
||||
await this._harmony.sendCommand(JSON.stringify(command));
|
||||
|
||||
//Sleep
|
||||
await sleep(800);
|
||||
} catch (err) {
|
||||
this._log(`ERROR - error sending command to harmony: ${err}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user