Skip to content

Commit

Permalink
Only retrieve details for devices that have not been paired yet
Browse files Browse the repository at this point in the history
  • Loading branch information
JELoohuis committed Sep 16, 2024
1 parent add5992 commit f1e8544
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/TuyaOAuth2Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ export default class TuyaOAuth2Client extends OAuth2Client<TuyaOAuth2Token> {
this.onUpdateWebhook();
}

isRegistered(productId: string, deviceId: string, other = false): boolean {
const register = other ? this.registeredOtherDevices : this.registeredDevices;
return register.has(`${productId}:${deviceId}`);
}

onUpdateWebhook(): void {
if (this.__updateWebhookTimeout) {
this.homey.clearTimeout(this.__updateWebhookTimeout);
Expand Down
7 changes: 5 additions & 2 deletions lib/TuyaOAuth2Driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ export default class TuyaOAuth2Driver extends OAuth2Driver<TuyaOAuth2Client> {
async onPairListDevices({ oAuth2Client }: { oAuth2Client: TuyaOAuth2Client }): Promise<OAuth2DeviceResult[]> {
const devices = await oAuth2Client.getDevices();
const filteredDevices = devices.filter(device => {
this.log('Device:', JSON.stringify(TuyaOAuth2Util.redactFields(device)));
return this.onTuyaPairListDeviceFilter(device);
return !oAuth2Client.isRegistered(device.product_id, device.id) && this.onTuyaPairListDeviceFilter(device);
});
const listDevices: OAuth2DeviceResult[] = [];

this.log('Listing devices to pair:');

for (const device of filteredDevices) {
this.log('Device:', JSON.stringify(TuyaOAuth2Util.redactFields(device)));
const deviceSpecs =
(await oAuth2Client
.getSpecification(device.id)
Expand Down

0 comments on commit f1e8544

Please sign in to comment.