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

Replace switchbot wait with utility function #674

Merged
merged 1 commit into from
Feb 11, 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
4 changes: 2 additions & 2 deletions src/device/blindtilt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ export class BlindTilt {
}
};
// Wait
return await switchbot.wait(this.scanDuration * 1000);
return await sleep(this.scanDuration * 1000);
})
.then(async () => {
// Stop to monitor
Expand Down Expand Up @@ -940,7 +940,7 @@ export class BlindTilt {
switchbot.onadvertisement = (ad: any) => {
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
};
await switchbot.wait(10000);
await sleep(10000);
// Stop to monitor
switchbot.stopScan();
})();
Expand Down
4 changes: 2 additions & 2 deletions src/device/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ export class Bot {
}
};
// Wait
return await switchbot.wait(this.scanDuration * 1000);
return await sleep(this.scanDuration * 1000);
})
.then(async () => {
// Stop to monitor
Expand Down Expand Up @@ -1150,7 +1150,7 @@ export class Bot {
switchbot.onadvertisement = (ad: any) => {
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
};
await switchbot.wait(10000);
await sleep(10000);
// Stop to monitor
switchbot.stopScan();
})();
Expand Down
4 changes: 2 additions & 2 deletions src/device/ceilinglight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ export class CeilingLight {
}
};
// Wait
return await switchbot.wait(this.scanDuration * 1000);
return await sleep(this.scanDuration * 1000);
})
.then(async () => {
// Stop to monitor
Expand Down Expand Up @@ -943,7 +943,7 @@ export class CeilingLight {
switchbot.onadvertisement = (ad: any) => {
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
};
await switchbot.wait(10000);
await sleep(10000);
// Stop to monitor
switchbot.stopScan();
})();
Expand Down
4 changes: 2 additions & 2 deletions src/device/colorbulb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ export class ColorBulb {
}
};
// Wait
return await switchbot.wait(this.scanDuration * 1000);
return await sleep(this.scanDuration * 1000);
})
.then(async () => {
// Stop to monitor
Expand Down Expand Up @@ -1100,7 +1100,7 @@ export class ColorBulb {
switchbot.onadvertisement = (ad: any) => {
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
};
await switchbot.wait(10000);
await sleep(10000);
// Stop to monitor
switchbot.stopScan();
})();
Expand Down
5 changes: 3 additions & 2 deletions src/device/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { SwitchBotPlatform } from '../platform';
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
import { device, devicesConfig, serviceData, switchbot, deviceStatus, ad, HostDomain, DevicePath } from '../settings';
import { IncomingMessage } from 'http';
import { sleep } from '../utils';

/**
* Platform Accessory
Expand Down Expand Up @@ -347,7 +348,7 @@ export class Contact {
}
};
// Wait
return await switchbot.wait(this.scanDuration * 1000);
return await sleep(this.scanDuration * 1000);
})
.then(async () => {
// Stop to monitor
Expand Down Expand Up @@ -490,7 +491,7 @@ export class Contact {
switchbot.onadvertisement = (ad: any) => {
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
};
await switchbot.wait(10000);
await sleep(10000);
// Stop to monitor
switchbot.stopScan();
})();
Expand Down
4 changes: 2 additions & 2 deletions src/device/curtain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ export class Curtain {
}
};
// Wait
return await switchbot.wait(this.scanDuration * 1000);
return await sleep(this.scanDuration * 1000);
})
.then(async () => {
// Stop to monitor
Expand Down Expand Up @@ -866,7 +866,7 @@ export class Curtain {
switchbot.onadvertisement = (ad: any) => {
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
};
await switchbot.wait(10000);
await sleep(10000);
// Stop to monitor
switchbot.stopScan();
})();
Expand Down
5 changes: 3 additions & 2 deletions src/device/humidifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { SwitchBotPlatform } from '../platform';
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
import { device, devicesConfig, serviceData, ad, deviceStatus, HostDomain, DevicePath } from '../settings';
import { sleep } from '../utils';

/**
* Platform Accessory
Expand Down Expand Up @@ -343,7 +344,7 @@ export class Humidifier {
}
};
// Wait
return await switchbot.wait(this.scanDuration * 1000);
return await sleep(this.scanDuration * 1000);
})
.then(async () => {
// Stop to monitor
Expand Down Expand Up @@ -791,7 +792,7 @@ export class Humidifier {
switchbot.onadvertisement = (ad: any) => {
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
};
await switchbot.wait(10000);
await sleep(10000);
// Stop to monitor
switchbot.stopScan();
})();
Expand Down
5 changes: 3 additions & 2 deletions src/device/lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { SwitchBotPlatform } from '../platform';
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
import { device, devicesConfig, deviceStatus, HostDomain, DevicePath, switchbot, ad, serviceData } from '../settings';
import { sleep } from '../utils';

export class Lock {
// Services
Expand Down Expand Up @@ -274,7 +275,7 @@ export class Lock {
}
};
// Wait
return await switchbot.wait(this.scanDuration * 1000);
return await sleep(this.scanDuration * 1000);
})
.then(async () => {
// Stop to monitor
Expand Down Expand Up @@ -533,7 +534,7 @@ export class Lock {
switchbot.onadvertisement = (ad: any) => {
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
};
await switchbot.wait(10000);
await sleep(10000);
// Stop to monitor
switchbot.stopScan();
})();
Expand Down
5 changes: 3 additions & 2 deletions src/device/meter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { SwitchBotPlatform } from '../platform';
import { Service, PlatformAccessory, Units, CharacteristicValue } from 'homebridge';
import { device, devicesConfig, serviceData, ad, switchbot, temperature, deviceStatus, HostDomain, DevicePath } from '../settings';
import { IncomingMessage } from 'http';
import { sleep } from '../utils';

/**
* Platform Accessory
Expand Down Expand Up @@ -304,7 +305,7 @@ export class Meter {
}
};
// Wait
return await switchbot.wait(this.scanDuration * 1000);
return await sleep(this.scanDuration * 1000);
})
.then(async () => {
// Stop to monitor
Expand Down Expand Up @@ -515,7 +516,7 @@ export class Meter {
switchbot.onadvertisement = (ad: any) => {
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
};
await switchbot.wait(10000);
await sleep(10000);
// Stop to monitor
switchbot.stopScan();
})();
Expand Down
5 changes: 3 additions & 2 deletions src/device/meterplus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { SwitchBotPlatform } from '../platform';
import { Service, PlatformAccessory, Units, CharacteristicValue } from 'homebridge';
import { device, devicesConfig, serviceData, ad, switchbot, temperature, deviceStatus, HostDomain, DevicePath } from '../settings';
import { IncomingMessage } from 'http';
import { sleep } from '../utils';

/**
* Platform Accessory
Expand Down Expand Up @@ -305,7 +306,7 @@ export class MeterPlus {
}
};
// Wait
return await switchbot.wait(this.scanDuration * 1000);
return await sleep(this.scanDuration * 1000);
})
.then(async () => {
// Stop to monitor
Expand Down Expand Up @@ -515,7 +516,7 @@ export class MeterPlus {
switchbot.onadvertisement = (ad: any) => {
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
};
await switchbot.wait(10000);
await sleep(10000);
// Stop to monitor
switchbot.stopScan();
})();
Expand Down
4 changes: 2 additions & 2 deletions src/device/motion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ export class Motion {
}
};
// Wait
return await switchbot.wait(this.scanDuration * 1000);
return await sleep(this.scanDuration * 1000);
},
});
})
Expand Down Expand Up @@ -440,7 +440,7 @@ export class Motion {
switchbot.onadvertisement = (ad: any) => {
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
};
await switchbot.wait(10000);
await sleep(10000);
// Stop to monitor
switchbot.stopScan();
})();
Expand Down
4 changes: 2 additions & 2 deletions src/device/plug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export class Plug {
}
};
// Wait
return await switchbot.wait(this.scanDuration * 1000);
return await sleep(this.scanDuration * 1000);
})
.then(async () => {
// Stop to monitor
Expand Down Expand Up @@ -499,7 +499,7 @@ export class Plug {
switchbot.onadvertisement = (ad: any) => {
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
};
await switchbot.wait(10000);
await sleep(10000);
// Stop to monitor
switchbot.stopScan();
})();
Expand Down
4 changes: 2 additions & 2 deletions src/device/robotvacuumcleaner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export class RobotVacuumCleaner {
}
};
// Wait
return await switchbot.wait(this.scanDuration * 1000);
return await sleep(this.scanDuration * 1000);
})
.then(async () => {
// Stop to monitor
Expand Down Expand Up @@ -623,7 +623,7 @@ export class RobotVacuumCleaner {
switchbot.onadvertisement = (ad: any) => {
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
};
await switchbot.wait(10000);
await sleep(10000);
// Stop to monitor
switchbot.stopScan();
})();
Expand Down
4 changes: 2 additions & 2 deletions src/device/striplight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ export class StripLight {
}
};
// Wait
return await switchbot.wait(this.scanDuration * 1000);
return await sleep(this.scanDuration * 1000);
})
.then(async () => {
// Stop to monitor
Expand Down Expand Up @@ -864,7 +864,7 @@ export class StripLight {
switchbot.onadvertisement = (ad: any) => {
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
};
await switchbot.wait(10000);
await sleep(10000);
// Stop to monitor
switchbot.stopScan();
})();
Expand Down