From 4c0419a354e128164f1853658c58da3a2e96df38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Thu, 7 Sep 2023 16:44:54 +0200 Subject: [PATCH] Unpair devices after pulling schema --- .gitignore | 1 + src/routes/pull-schema.ts | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/.gitignore b/.gitignore index 1afb9fd..ad85753 100644 --- a/.gitignore +++ b/.gitignore @@ -266,3 +266,4 @@ dist # End of https://www.toptal.com/developers/gitignore/api/node,visualstudiocode,intellij+all,git .wrangler/ +.dev.vars diff --git a/src/routes/pull-schema.ts b/src/routes/pull-schema.ts index a8ee04d..3ea9468 100644 --- a/src/routes/pull-schema.ts +++ b/src/routes/pull-schema.ts @@ -41,6 +41,7 @@ type ResponseData = { modelResponse: ObjectType detailsResponse: ObjectType updateResponse: ObjectType + deleteResponse: boolean errors: string[] } @@ -229,6 +230,15 @@ export async function pullSchema( errors.push(`${e}`) } + // unpair the device to make switching category possible + try { + responseContext.deleteResponse = await unpack( + tuya.device.delete({ device_id: devId }), + ) + } catch (e) { + errors.push(`${e}`) + } + responseContext.cachedAt = Date.now() responseContext.cacheKey = productKey