Added initial homebridge setup

This commit is contained in:
watsonb8
2019-09-01 15:25:53 -04:00
parent be02f8f8d2
commit b20d657674
11 changed files with 671 additions and 0 deletions

30
src/Util/Callbackify.ts Normal file
View File

@@ -0,0 +1,30 @@
/**
* Helper function to convert callbacks into promises
* @param func
*/
export default function callbackify(func: (...args: any[]) => Promise<any>): Function {
return (...args: any[]) => {
const onlyArgs: any[] = [];
let maybeCallback: Function | null = null;
for (const arg of args) {
if (typeof arg === 'function') {
maybeCallback = arg;
break;
}
onlyArgs.push(arg);
}
if (!maybeCallback) {
throw new Error("Missing callback parameter!");
}
const callback = maybeCallback;
func(...onlyArgs)
.then((data: any) => callback(null, data))
.catch((err: any) => callback(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));
}