Added a delay between commands. Fixed issue where inputs were not being set correctly.

This commit is contained in:
watsonb8 2019-06-23 11:42:10 -04:00
parent 8bb65b5b3c
commit 0ea4188487
2 changed files with 10 additions and 3 deletions

View File

@ -2,6 +2,7 @@ import { Activity } from "../Models/Activity";
import { DeviceSetupItem } from "../Models/DeviceSetupItem"; import { DeviceSetupItem } from "../Models/DeviceSetupItem";
import { Input, Matrix, Output } from "../Models/Matrix"; import { Input, Matrix, Output } from "../Models/Matrix";
import { RemoteKey } from '../Accessories/ControlUnit'; import { RemoteKey } from '../Accessories/ControlUnit';
import { sleep } from '../Util/Sleep';
let Characteristic: HAPNodeJS.Characteristic; let Characteristic: HAPNodeJS.Characteristic;
@ -122,8 +123,8 @@ class HarmonyDataProvider {
activity.deviceSetupItems.map(async (value: DeviceSetupItem) => { activity.deviceSetupItems.map(async (value: DeviceSetupItem) => {
let device: IDevice = this.getDeviceFromName(value.deviceName); let device: IDevice = this.getDeviceFromName(value.deviceName);
if (device && device.supportsCommand(`Input${value.input}`)) { if (device && device.supportsCommand(`Input ${value.input}`)) {
let command: string = device.getCommand(`Input${value.input}`); let command: string = device.getCommand(`Input ${value.input}`);
await this.sendCommand(command); await this.sendCommand(command);
} }
}) })
@ -389,8 +390,11 @@ class HarmonyDataProvider {
*/ */
private sendCommand = async (command: string) => { private sendCommand = async (command: string) => {
try { try {
//Execute command
let response = await this.harmony.sendCommand(JSON.stringify(command)); let response = await this.harmony.sendCommand(JSON.stringify(command));
// this.log(`Sent command: ${JSON.stringify(command)} response: ${JSON.stringify(response)}`);
//Sleep
await sleep(800);
} catch (err) { } catch (err) {
this.log(`ERROR - error sending command to harmony: ${err}`); this.log(`ERROR - error sending command to harmony: ${err}`);
} }

3
src/Util/Sleep.ts Normal file
View File

@ -0,0 +1,3 @@
export function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}