Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix async method calls #690

Merged
merged 2 commits into from
Mar 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/device/blindtilt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,8 @@ export class BlindTilt {
this.infoLog(`${this.accessory.displayName} Target Position: ${this.TargetPosition}`);
return await this.retry({
max: await this.maxRetry(),
fn: () => {
return device_list[0].runToPos(100 - Number(this.TargetPosition), adjustedMode);
fn: async () => {
return await device_list[0].runToPos(100 - Number(this.TargetPosition), adjustedMode);
},
});
})
Expand All @@ -640,11 +640,11 @@ export class BlindTilt {
}

async retry({ max, fn }: { max: number; fn: { (): any; (): Promise<any> } }): Promise<null> {
return fn().catch(async (err: any) => {
return fn().catch(async (e: any) => {
if (max === 0) {
throw err;
throw e;
}
this.infoLog(err);
this.infoLog(e);
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Retrying`);
await sleep(1000);
return this.retry({ max: max - 1, fn });
Expand Down
16 changes: 8 additions & 8 deletions src/device/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,9 @@ export class Bot {
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
switchbot
.discover({ model: 'H', quick: true, id: this.device.bleMac })
.then((device_list: { press: (arg0: { id: string | undefined }) => any }[]) => {
.then(async (device_list: { press: (arg0: { id: string | undefined }) => any }[]) => {
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
return device_list[0].press({ id: this.device.bleMac });
return await device_list[0].press({ id: this.device.bleMac });
})
.then(() => {
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
Expand Down Expand Up @@ -660,11 +660,11 @@ export class Bot {
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
return await this.retry({
max: await this.maxRetry(),
fn: () => {
fn: async () => {
if (this.On) {
return device_list[0].turnOn({ id: this.device.bleMac });
return await device_list[0].turnOn({ id: this.device.bleMac });
} else {
return device_list[0].turnOff({ id: this.device.bleMac });
return await device_list[0].turnOff({ id: this.device.bleMac });
}
},
});
Expand Down Expand Up @@ -1173,11 +1173,11 @@ export class Bot {
}

async retry({ max, fn }: { max: number; fn: { (): any; (): Promise<any> } }): Promise<null> {
return fn().catch(async (err: any) => {
return fn().catch(async (e: any) => {
if (max === 0) {
throw err;
throw e;
}
this.infoLog(err);
this.infoLog(e);
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Retrying`);
await sleep(1000);
return this.retry({ max: max - 1, fn });
Expand Down
12 changes: 6 additions & 6 deletions src/device/ceilinglight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,11 +493,11 @@ export class CeilingLight {
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
return await this.retry({
max: await this.maxRetry(),
fn: () => {
fn: async () => {
if (this.On) {
return device_list[0].turnOn({ id: this.device.bleMac });
return await device_list[0].turnOn({ id: this.device.bleMac });
} else {
return device_list[0].turnOff({ id: this.device.bleMac });
return await device_list[0].turnOff({ id: this.device.bleMac });
}
},
});
Expand Down Expand Up @@ -966,11 +966,11 @@ export class CeilingLight {
}

async retry({ max, fn }: { max: number; fn: { (): any; (): Promise<any> } }): Promise<null> {
return fn().catch(async (err: any) => {
return fn().catch(async (e: any) => {
if (max === 0) {
throw err;
throw e;
}
this.infoLog(err);
this.infoLog(e);
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Retrying`);
await sleep(1000);
return this.retry({ max: max - 1, fn });
Expand Down
24 changes: 12 additions & 12 deletions src/device/colorbulb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,11 +528,11 @@ export class ColorBulb {
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
return await this.retry({
max: await this.maxRetry(),
fn: () => {
fn: async () => {
if (this.On) {
return device_list[0].turnOn({ id: this.device.bleMac });
return await device_list[0].turnOn({ id: this.device.bleMac });
} else {
return device_list[0].turnOff({ id: this.device.bleMac });
return await device_list[0].turnOff({ id: this.device.bleMac });
}
},
});
Expand Down Expand Up @@ -580,9 +580,9 @@ export class ColorBulb {
model: 'u',
id: this.device.bleMac,
})
.then((device_list: any) => {
.then(async (device_list: any) => {
this.infoLog(`${this.accessory.displayName} Target Brightness: ${this.Brightness}`);
return device_list[0].setBrightness(this.Brightness);
return await device_list[0].setBrightness(this.Brightness);
})
.then(() => {
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
Expand Down Expand Up @@ -615,9 +615,9 @@ export class ColorBulb {
model: 'u',
id: this.device.bleMac,
})
.then((device_list: any) => {
.then(async (device_list: any) => {
this.infoLog(`${this.accessory.displayName} Target ColorTemperature: ${this.ColorTemperature}`);
return device_list[0].setColorTemperature(this.ColorTemperature);
return await device_list[0].setColorTemperature(this.ColorTemperature);
})
.then(() => {
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
Expand Down Expand Up @@ -657,9 +657,9 @@ export class ColorBulb {
model: 'u',
id: this.device.bleMac,
})
.then((device_list: any) => {
.then(async (device_list: any) => {
this.infoLog(`${this.accessory.displayName} Target RGB: ${this.Brightness, red, green, blue}`);
return device_list[0].setRGB(this.Brightness, red, green, blue);
return await device_list[0].setRGB(this.Brightness, red, green, blue);
})
.then(() => {
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
Expand Down Expand Up @@ -1123,11 +1123,11 @@ export class ColorBulb {
}

async retry({ max, fn }: { max: number; fn: { (): any; (): Promise<any> } }): Promise<null> {
return fn().catch(async (err: any) => {
return fn().catch(async (e: any) => {
if (max === 0) {
throw err;
throw e;
}
this.infoLog(err);
this.infoLog(e);
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Retrying`);
await sleep(1000);
return this.retry({ max: max - 1, fn });
Expand Down
10 changes: 5 additions & 5 deletions src/device/curtain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,8 @@ export class Curtain {
this.infoLog(`${this.accessory.displayName} Target Position: ${this.TargetPosition}`);
return await this.retry({
max: await this.maxRetry(),
fn: () => {
return device_list[0].runToPos(100 - Number(this.TargetPosition), adjustedMode);
fn: async () => {
return await device_list[0].runToPos(100 - Number(this.TargetPosition), adjustedMode);
},
});
})
Expand All @@ -601,11 +601,11 @@ export class Curtain {
}

async retry({ max, fn }: { max: number; fn: { (): any; (): Promise<any> } }): Promise<null> {
return fn().catch(async (err: any) => {
return fn().catch(async (e: any) => {
if (max === 0) {
throw err;
throw e;
}
this.infoLog(err);
this.infoLog(e);
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Retrying`);
await sleep(1000);
return this.retry({ max: max - 1, fn });
Expand Down
4 changes: 2 additions & 2 deletions src/device/humidifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,9 @@ export class Humidifier {
quick: true,
id: this.device.bleMac,
})
.then((device_list: any) => {
.then(async (device_list: any) => {
this.infoLog(`${this.accessory.displayName} Target Position: ${this.Active}`);
return device_list[0].percentage(this.RelativeHumidityHumidifierThreshold);
return await device_list[0].percentage(this.RelativeHumidityHumidifierThreshold);
})
.then(() => {
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
Expand Down
6 changes: 3 additions & 3 deletions src/device/motion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,11 @@ export class Motion {
}

async retry({ max, fn }: { max: number; fn: { (): any; (): Promise<any> } }): Promise<null> {
return fn().catch(async (err: any) => {
return fn().catch(async (e: any) => {
if (max === 0) {
throw err;
throw e;
}
this.infoLog(err);
this.infoLog(e);
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Retrying`);
await sleep(1000);
return this.retry({ max: max - 1, fn });
Expand Down
12 changes: 6 additions & 6 deletions src/device/plug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,11 @@ export class Plug {
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
return await this.retry({
max: await this.maxRetry(),
fn: () => {
fn: async () => {
if (this.On) {
return device_list[0].turnOn({ id: this.device.bleMac });
return await device_list[0].turnOn({ id: this.device.bleMac });
} else {
return device_list[0].turnOff({ id: this.device.bleMac });
return await device_list[0].turnOff({ id: this.device.bleMac });
}
},
});
Expand Down Expand Up @@ -522,11 +522,11 @@ export class Plug {
}

async retry({ max, fn }: { max: number; fn: { (): any; (): Promise<any> } }): Promise<null> {
return fn().catch(async (err: any) => {
return fn().catch(async (e: any) => {
if (max === 0) {
throw err;
throw e;
}
this.infoLog(err);
this.infoLog(e);
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Retrying`);
await sleep(1000);
return this.retry({ max: max - 1, fn });
Expand Down
12 changes: 6 additions & 6 deletions src/device/robotvacuumcleaner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,11 @@ export class RobotVacuumCleaner {
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
return await this.retry({
max: await this.maxRetry(),
fn: () => {
fn: async () => {
if (this.On) {
return device_list[0].turnOn({ id: this.device.bleMac });
return await device_list[0].turnOn({ id: this.device.bleMac });
} else {
return device_list[0].turnOff({ id: this.device.bleMac });
return await device_list[0].turnOff({ id: this.device.bleMac });
}
},
});
Expand Down Expand Up @@ -646,11 +646,11 @@ export class RobotVacuumCleaner {
}

async retry({ max, fn }: { max: number; fn: { (): any; (): Promise<any> } }): Promise<null> {
return fn().catch(async (err: any) => {
return fn().catch(async (e: any) => {
if (max === 0) {
throw err;
throw e;
}
this.infoLog(err);
this.infoLog(e);
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Retrying`);
await sleep(1000);
return this.retry({ max: max - 1, fn });
Expand Down
20 changes: 10 additions & 10 deletions src/device/striplight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,11 +468,11 @@ export class StripLight {
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
return await this.retry({
max: await this.maxRetry(),
fn: () => {
fn: async () => {
if (this.On) {
return device_list[0].turnOn({ id: this.device.bleMac });
return await device_list[0].turnOn({ id: this.device.bleMac });
} else {
return device_list[0].turnOff({ id: this.device.bleMac });
return await device_list[0].turnOff({ id: this.device.bleMac });
}
},
});
Expand Down Expand Up @@ -516,9 +516,9 @@ export class StripLight {
model: 'u',
id: this.device.bleMac,
})
.then((device_list: any) => {
.then(async (device_list: any) => {
this.infoLog(`${this.accessory.displayName} Target Brightness: ${this.Brightness}`);
return device_list[0].setBrightness(this.Brightness);
return await device_list[0].setBrightness(this.Brightness);
})
.then(() => {
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
Expand Down Expand Up @@ -557,9 +557,9 @@ export class StripLight {
model: 'u',
id: this.device.bleMac,
})
.then((device_list: any) => {
.then(async (device_list: any) => {
this.infoLog(`${this.accessory.displayName} Target RGB: ${this.Brightness, red, green, blue}`);
return device_list[0].setRGB(this.Brightness, red, green, blue);
return await device_list[0].setRGB(this.Brightness, red, green, blue);
})
.then(() => {
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
Expand Down Expand Up @@ -887,11 +887,11 @@ export class StripLight {
}

async retry({ max, fn }: { max: number; fn: { (): any; (): Promise<any> } }): Promise<null> {
return fn().catch(async (err: any) => {
return fn().catch(async (e: any) => {
if (max === 0) {
throw err;
throw e;
}
this.infoLog(err);
this.infoLog(e);
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Retrying`);
await sleep(1000);
return this.retry({ max: max - 1, fn });
Expand Down