From 0ea4188487df433925f4b4c36216b75626582346 Mon Sep 17 00:00:00 2001 From: watsonb8 Date: Sun, 23 Jun 2019 11:42:10 -0400 Subject: [PATCH] Added a delay between commands. Fixed issue where inputs were not being set correctly. --- src/DataProviders/HarmonyDataProvider.ts | 10 +++++++--- src/Util/Sleep.ts | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 src/Util/Sleep.ts diff --git a/src/DataProviders/HarmonyDataProvider.ts b/src/DataProviders/HarmonyDataProvider.ts index 66db933..75b1012 100644 --- a/src/DataProviders/HarmonyDataProvider.ts +++ b/src/DataProviders/HarmonyDataProvider.ts @@ -2,6 +2,7 @@ import { Activity } from "../Models/Activity"; import { DeviceSetupItem } from "../Models/DeviceSetupItem"; import { Input, Matrix, Output } from "../Models/Matrix"; import { RemoteKey } from '../Accessories/ControlUnit'; +import { sleep } from '../Util/Sleep'; let Characteristic: HAPNodeJS.Characteristic; @@ -122,8 +123,8 @@ class HarmonyDataProvider { activity.deviceSetupItems.map(async (value: DeviceSetupItem) => { let device: IDevice = this.getDeviceFromName(value.deviceName); - if (device && device.supportsCommand(`Input${value.input}`)) { - let command: string = device.getCommand(`Input${value.input}`); + if (device && device.supportsCommand(`Input ${value.input}`)) { + let command: string = device.getCommand(`Input ${value.input}`); await this.sendCommand(command); } }) @@ -389,8 +390,11 @@ class HarmonyDataProvider { */ private sendCommand = async (command: string) => { try { + //Execute 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) { this.log(`ERROR - error sending command to harmony: ${err}`); } diff --git a/src/Util/Sleep.ts b/src/Util/Sleep.ts new file mode 100644 index 0000000..9721cc4 --- /dev/null +++ b/src/Util/Sleep.ts @@ -0,0 +1,3 @@ +export function sleep(ms: number) { + return new Promise(resolve => setTimeout(resolve, ms)); +} \ No newline at end of file