From f1e85442df69a9a8af95c4ddc8ca7ab1ae68add0 Mon Sep 17 00:00:00 2001 From: Joost Loohuis Date: Mon, 16 Sep 2024 14:26:10 +0200 Subject: [PATCH] Only retrieve details for devices that have not been paired yet --- lib/TuyaOAuth2Client.ts | 5 +++++ lib/TuyaOAuth2Driver.ts | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/TuyaOAuth2Client.ts b/lib/TuyaOAuth2Client.ts index 65dd623..1390925 100644 --- a/lib/TuyaOAuth2Client.ts +++ b/lib/TuyaOAuth2Client.ts @@ -328,6 +328,11 @@ export default class TuyaOAuth2Client extends OAuth2Client { 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); diff --git a/lib/TuyaOAuth2Driver.ts b/lib/TuyaOAuth2Driver.ts index 295533d..0ef466f 100644 --- a/lib/TuyaOAuth2Driver.ts +++ b/lib/TuyaOAuth2Driver.ts @@ -31,11 +31,14 @@ export default class TuyaOAuth2Driver extends OAuth2Driver { async onPairListDevices({ oAuth2Client }: { oAuth2Client: TuyaOAuth2Client }): Promise { 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)